Hello, Im using Bitbucket API and the JS Object. Im attempting to get data from a subquery using a stored value from the parent query. My second query seems to be returning the same data for every object in the forEach loop. When including the appsmith.store.repoName output I noticed its not using the correct value, but seems to be using the last repoName that was returned from the first query (getRepositories).
The below is getting all the repositories from bitbucket, then foreach of these, its attempting to pull down the envionrment list for this repository. (Im then trying to get the uuid value from this subquery if its a production environment)
const result = await getRepositories.run()
result.data.values.forEach((repo) => {...});
Bascially, what I’m suggesting is that you run the queries first with an await and store the response in a variable, then use the variables as you wish.
Thanks Olawale, this suggestion did solve my issue but ive run into another, the loop now runs sequentially, it does work and pull back the correct data I need but is slow, when trying to use promise.all im having problems with the appsmith.store variables.
How does the appsmith.store handle variables set in async functions?
It seems to be overridding the variables.
Is there a way I can use the appsmith.store to store variables to be accessed in the API calls URL where they are called in parallel?
If i was to run the main loop one at a time, this works just fine but is very slow as the number of repos i’m going over is high, Ideally my goal is to have all the items in the repoList main loop run in parallel.
Hi there! Although this isn’t working the way you want it to, It’s working as I expect it to.
Promise.all() is a promise concurrency method and what you’re experiencing is a data race issue. Somehow, they’re all holding the same reference to the variable when they’re about to be executed.
If you try this without promise.all(), you’ll realise that they work perfectly so, this isn’t really an issue with appsmith, it’s just a semantic issue.
One solution I can recommend is to pass repo as a parameter to the function like so:
for (let i = 0; i < repoList.length; i++) {
const repo = repoList[i];
promises.push((async (repoID) => {...})(repo));
}
and then you reference the repoID within those functions. Can you try that and see if it works?
Hey Kelly!
It might be a bit tedious to provide any example that will be inline with your use case right now.
Could you invite support@appsmith.com as Developer to your workspace and share the link to your app with us so we can debug it?