Can transformer access additionalScope?

since upload file need to transform the data, working on multiple file upload, need to merge the additionalScope as part of the array

Unfortunately, additionalScope is not currently available inside of a transformer (I will file a bug report for this). Would you mind sharing the javascript query that you are currently using to upload your files? We might be able to find a workaround for this.

1 Like

I have a javascript that loop through an array to triggers an API resources query with AdditionalScope.
Once the API completed it will trigger another javascript, but seems like cannot access the AdditionalScope value, it always return the first value from the array

Hey, is it possible to provide a screenshot of some kind?

No errors, just that the parameter is always return the first value.

I have a js like this

 function go() {
    for (let i = 0; i < fileDropzone.files.length; i++) {
    let x = { data: fileDropzone.value[i],...fileDropzone.files[i] }
           apiUploadFile.trigger({ additionalScope: { i: i,d: x },      
 return go()

on my apiUploadFile Rest API Resources end, I can make use of {{i}} to loop through the array.
But if I create another js that trigger when the API Successful event, I can't access the {{i}} any more

Hey how are you triggering the other JS, is the other JS a transformer within apiUploadFile or is it a query that gets triggered within apiUploadFile, or are you passing into apiUploadFile.trigger with onSuccess? Its a little strange that there isn't an errors thrown because if it has to do with the additional scope being not available it should throw that something isn't defined.

I trigger other js when apiUploadFile on success. There is no error, it works, but the {{i}} always return 0 only, which is the first index value in the loop.

In the browser console when the query triggers are being logged, it should show the additionalScope that is passed in each of those .trigger() methods- Do they all show a 0 being passed?

it passed the additional scope nicely because the API insert the correct records, but the js launch after successful call just returns the first value for each call.

Where is the on success trigger being defined? The i variable won’t automatically be passed to queries that are triggered after the first .trigger(), it would need to be explicitly passed inside of an onSuccess function inside of the .trigger() method.

If a query triggers another query in an event handler afterwards, the additional scope passed to that first query wouldn’t be automatically passed along.

i is a magic variable that is populated from components that might trigger from an index, like a table or listview, and the default value of i is 0. If your setup is like I outlined here, if you rename your additionalScope variable in your current setup I would expect to start getting “x is undefined” errors.

understand, which is what I try to find out, is there any way I can pass the additionalscope over to the js that run onsuccess?

In this setup, both the targetQuery and queryToRunAfterTargetQuery would receive a key additonalScope value of 123:

const value = 123

additionalScope: {key: value},
onSuccess: (data) => {
additionalScope: {key: value, resultFromTargetQuery: data}

You can also pass in the data of targetQuery as additionalScope into the following query for scenarios when you would want to trigger these many times and keep the previous result in sync with the query being triggered after

yes, this is my workaround, what I try to say is I can't setup a js script run on the API onsuccess call through the GUI right? the additionaalscope won't pass over

This is correct- the event handler doesn't offer additional scope yet but that would be a good addition!

Although actually, you can pretty easily do this with the Run Script action: