I want to perform a query multiple times. I am iterating over an array and performing the query and passing the additional scope.
Said query is a resource (OpenAPI). However, I can't figure out how to access this additional scope in my query.
I want to perform a query multiple times. I am iterating over an array and performing the query and passing the additional scope.
Said query is a resource (OpenAPI). However, I can't figure out how to access this additional scope in my query.
I built this one with chatgpt awhile ago. It iterates over locations and triggers the query with the addtional scope of 'requestBody'
it returns all responses in a promise once completed. Should be accessible in query.data
You want to trigger the JS query that triggers your openAPI query and not the other way around.
const locations = destinations.value;
const query = createInboundShipmentPlan; // Replace with your query name
// Array to store the promises
const promises = locations.map((location, index) => {
const randomZip = getRandomElement(location.zip_codes); // Pick a random zip code for each location
const payload = {
};
// Return a delayed promise
return new Promise((resolve) => {
setTimeout(() => {
query.trigger({
additionalScope: { requestBody: payload }
}).then(response => {
console.log("Response for", payload.City, payload.StateOrProvinceCode, payload.PostalCode, ":", response);
resolve(response); // Resolve the promise with the response
}).catch(error => {
console.error("Error for", payload.City, payload.StateOrProvinceCode, payload.PostalCode, ":", error);
resolve(error); // Resolve with error to continue all promises
});
}, index * 3000); // Delay each request by 3 seconds
});
});
// Wait for all promises to resolve and return the responses
return Promise.all(promises);
Here is a simple code:
table1.selectedRows.forEach(fileId => {
deleteFile.trigger( {additionalScope:{id:fileId.id} } )
})
Hi Nick, thank you for your help.
I am getting an error for my propertyId
Error:propertyId is not defined
I see you are also defining your requestBody as one of the Query parameters. Doesn't that cause an error for you?
Are you running the OpenAPI query? If so then yes it would say that.
Youre supposed to run a JS query that will trigger your OpenAPI query and pass along the additionalScope. You would compute your propertyId in the JS query.
Or youre not passing the propertyId in the appropriate scope. The query i provide you works for me you can probably just copy paste it into yours and change some things.
Hi @jrod Just checking in here Were you able to move forward with a solution? Thanks for your advice, @nickport !
Thanks to @nickport I was able to solve the issue. Thank you