Pass additionalScope data to onSuccess

I'm building a javascript query that calls a Microsoft Graph API for data related to a user.
The query is generic and I pass the userID into the additionalScope to make it specific to a user.
Unfortunately the resulting dataset from the API does not include the original userID, it only has the results so I don't know how to map the results to the specific userID for those results.

My code looks something like this:

users = ["1", "2"]; // Array of userIDs
let i=0; // in the future I would iterate overall user IDs, but I'm just doing one for simplicity

const myUserStatusPromise = new Promise(function(resolve, reject) {
      additionalScope: {userID; users[i]}, 
      onSuccess: {(data) => console.log(additionalScope.userID); resolve(data);}
myUserStatusPromise.then((data) => {
  console.log(`Status for user is ${data} for ${additionalScope.userID}`);

The part I'm trying to figure out is "additionalScope.userID". I made that up, it's not a valid property. I tried "this.additionalScope.userID" also. I can't see to get the additional scope properties in the onSuccess function nor in the resolve step. I looked at the docs Promise reTool docs but the example resolves all promises with Promise.all where the query result is returned but not the initial query request parameters.

Any ideas on how to access the additionalScope specific to the query that was run?

Hey @jessvin.thomas :wave:

You might try making a direct reference to users[i]! Something like:

const myUserStatusPromise = new Promise(function (resolve, reject) {
    additionalScope: { userID: users[i] },
    onSuccess: (data) => {
      resolve({ userID: users[i], data });
await myUserStatusPromise.then((result) => {
  console.log(`Status for user is ${} for ${result.userID}`);

does that work?

Thank you, that worked. Somehow I didn't think the correct iteration of i would propagate to onSuccess.

In doing this i realized, I might not even need a promise since OnSuccess is essentially a call back. However, ideally I want to create an array of promises and settle them all with Promise.all. I'm going to try that and report back. Thanks again.