Oct 14, 2024 09:32 AM
Hi Folks
I am a newbie to AirTable, so apologies if my question seems very basic.
My automation consists of an action script that calls an API for an external system, and if the API operation is successful, it sets the “Status” and “API_Response” fields in my AirTable to “continue next steps” and “Success” respectively.
Then, a conditional logic block is meant to check if "Success=continue next steps" and "API_Response=Success" and if these conditions are a match, a Create Record and Update Record actions are to be executed.
However, even when the API operation is successful, the conditional logic is not evaluating to true for some reason, when it should. As a result, the Create Record and Update Record actions are not being executed.
I have attached a screenshot showing the automation.
What am I doing wrong?
NOTE -
The code in the action script that updates the Status and API_Response columns is as follows:
Solved! Go to Solution.
Oct 14, 2024 02:14 PM - edited Oct 14, 2024 02:15 PM
Hi, and welcome to Airtable!
Is the condition for your conditional logic step using data from the initial trigger (when a button is clicked)? If so, it'll evaluate the condition based on the snapshot of the data at the time of the trigger -- so it won't register the changes made by your scripts later in the automation.
Since you're already using the Scripting action to catch whether the API call was successful, the easiest thing may be to add an output variable to your script during the IF block of that action. I would suggest something like:
if (response.status == 200) {
await airTableTab.updateRecordAsync(recordId,{"Status": {name: "continue next steps"}})
await airTableTab.updateRecordAsync(recordId,{"API_Response": "Success"})
output.set('continue', true)
}
Then you can set the condition(s) to use the 'continue' output variable in the scripting action:
You can customize the output variable (Step 5 here) to be a string instead of a boolean, or combine it with other conditions as usual, depending on how complex you need it to be. Note that you will probably have to run a test of the scripting action before it shows up as an option in the conditional.
Let me know if that works or if I can help troubleshoot further!
Best,
Rowan
Oct 14, 2024 02:14 PM - edited Oct 14, 2024 02:15 PM
Hi, and welcome to Airtable!
Is the condition for your conditional logic step using data from the initial trigger (when a button is clicked)? If so, it'll evaluate the condition based on the snapshot of the data at the time of the trigger -- so it won't register the changes made by your scripts later in the automation.
Since you're already using the Scripting action to catch whether the API call was successful, the easiest thing may be to add an output variable to your script during the IF block of that action. I would suggest something like:
if (response.status == 200) {
await airTableTab.updateRecordAsync(recordId,{"Status": {name: "continue next steps"}})
await airTableTab.updateRecordAsync(recordId,{"API_Response": "Success"})
output.set('continue', true)
}
Then you can set the condition(s) to use the 'continue' output variable in the scripting action:
You can customize the output variable (Step 5 here) to be a string instead of a boolean, or combine it with other conditions as usual, depending on how complex you need it to be. Note that you will probably have to run a test of the scripting action before it shows up as an option in the conditional.
Let me know if that works or if I can help troubleshoot further!
Best,
Rowan
Oct 15, 2024 06:35 AM - edited Oct 15, 2024 06:40 AM
Hi Rowan
You're a STAR !!🌟
It's good to learn that if my conditional logic is using data from the initial trigger then it will use the snapshot of data at that time. That is exactly what was happening in my case.
I have used the workaround you suggested and it is working like a charm now.
So thanks a million 🙏
Here's the updated code now:
//Evaluate if data table update has an error
if (response.status == 200) {
await airTableTab.updateRecordAsync(recordId,{"Status": {name: "continue next steps"}})
await airTableTab.updateRecordAsync(recordId,{"API_Response": "Success"})
output.set ("API_Response", "Success")
} else {
await airTableTab.updateRecordAsync(recordId,{"Status": {name: "failed"}})
await airTableTab.updateRecordAsync(recordId,{"API_Response": "failed"})
console.log(`JSON.stringify(response): ${JSON.stringify(trimmed_response)}`)
output.set ("API_Response","failed")
}