Trouble returning an array of objects containing results from a query

I'm trying to return an array of JSON objects using the results from a query, but I'm getting this error: Failed to execute 'postMessage' on 'Window': #<Promise> could not be cloned.

This is the Javascript query that I have.

var xsCount = extraSmallSizeAmount.value;

var xsSizeId = getSizeIdForName.trigger({
  additionalScope: {
    name: extraSmallSizeAmount.label,
  },
});

var skus = [
  {
    "xsSizeId": xsSizeId,
    "stock": xsCount
  }
];
return skus;

I'm able to return just the xsSizeId, so I can tell that the query I'm calling is returning the string correctly. Also able to see that xsCount is populating an int as I would expect. Individually, the pieces seem to all be fine, but when I create the object and try to return just that (even without the array), I get the error.

Any guidance would be appreciated!

Hey @cam_j!

Can you try adding await to the query trigger?

var xsSizeId = await getSizeIdForName.trigger({
  additionalScope: {
    name: extraSmallSizeAmount.label,
  },
});

Calling getSizeIdForName.trigger() should return a Promise, which can't be cloned and returned by the JavaScript query. When you return it by itself the JS query will wait for the Promise to resolve and then return the value it resolves to. Wrapping it in an object messes with that recognition though which can cause the error you're running into.

If you await the trigger you should just be dealing with the query data itself - let me know if that works?

Yes that was the issue! Thank you