I'm attempting to use a JS script to call some different queries, everything is working as expected with one exception.
This is the JS script, it calls the get_current_stage query to get the current step in the process. Then stores the column name in a variable to be used in the save_reflection_answer query which is called via event handler when the script successfully completes. All of this works properly.
get_current_stage.trigger
let the_stage = get_current_stage.data
let field_name = "Default"
if (the_stage.reflection_stage[0] === 1){
increment_stage.trigger
field_name = "morning_reflection_1"
}
if (the_stage.reflection_stage[0] === 2){
increment_stage.trigger
field_name = "morning_reflection_2"
}
return field_name
The only thing that isn't working is the increment_steps.trigger line which should be called when the appropriate if statement is satisfied. I know the if statements are being satisfied because the field_name vairable is being assigned the proper values, yet the increment_steps query isn't getting called.
This query works fine when manually run, it just isn't getting run from this function and I don't understand why.
While I much prefer @MiguelOrtiz 's solution I figured I'd go a head and show how to do it using the method you showed incase it's easier to understand:
// .trigger() returns a 'promise', we need to wait for it to finish running before we get the result so we use 'await'
let query_result = await get_current_stage.trigger();
// if the query is a retool db query you'll probably need to change below to query_result.data[0]
let the_stage = query_result.data
let field_name = "Default"
if (the_stage.reflection_stage[0] === 1){
increment_stage.trigger(); //if increment_stage returns results that we need, call use 'await increment_stage.trigger()' instead
field_name = "morning_reflection_1"
}
if (the_stage.reflection_stage[0] === 2){
increment_stage.trigger();
field_name = "morning_reflection_2"
}
return field_name