How to access additional scope from a Rest API query

  1. My goal:
    I'm trying to use multiline edition in a Retool table, triggering a Rest API query.

  2. Issue:
    In the save handler of my table, I have a script iterating the changeset and firing the PUT Rest API query for each one:

In the query, I try to access the additional scope as a variable, as seen in some other posts here -- but, as expected by any normal designer, the variable is not defined:

  1. Steps I've taken to troubleshoot:
    At first, the query used JSON type (not "raw"), as stated here. It didn't work. This post also seemed to be about this, but from a absotutelly mistaken point of view, as query.data contains the result of the query. Anyway, I also tried this and didn't work out.
1 Like

Hey @ironsand,

I think your syntax within additional scope is wrong, it should be ....additionalScope: {index:index}...

I.e. you're sending an object with properties and values, not only a single value.

I think this may be the issue

1 Like

I tried, and it is no the problem.

I was hoping this wasn't the problem, because in javascript (I don't know since which ECMAScript version, but for many years already) it's equivalent to declare the object { index: index } and the object {index}. So, if it didn't work because of this, it would be because retool is using really old JS or changed its behaviour.

Thanks for your time nonetheless <3

Some more debugging:
I've changed my script and put some console.logs: one before the for loop, one inside:

Strangely, it doesn't seem to enter the for loop, logging only the outer console.log call:

Does retool support for loops in custom scripts?

I believe the issue may be with your condition in the for loop.

You are checking index (int) against changesetArray (array). Might need to add the .length property and run again.

4 Likes

Thank you VERY much! Sometimes you get so stuck looking at the same screen, that the most obvious thing just goes unnoticed...

3 Likes

A forum of rubber ducks, we can be.

3 Likes