Help

Issue with Conditional Logic steps

Topic Labels: Automations
Solved
Jump to Solution
317 2
cancel
Showing results for 
Search instead for 
Did you mean: 
nishant_tank
4 - Data Explorer
4 - Data Explorer

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:

await airTableTab.updateRecordAsync(recordId,{"API_Response": "Success"})
 
//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"})
} else {
await airTableTab.updateRecordAsync(recordId,{"Status": {name: "failed"}})
await airTableTab.updateRecordAsync(recordId,{"API_Response": "failed"})
await airTableTab.updateRecordAsync(recordId,{"API_Response": JSON.stringify(trimmed_response)})
console.log(`JSON.stringify(response): ${JSON.stringify(trimmed_response)}`)
}

Screenshot 2024-10-14 at 16.59.58.png

 

1 Solution

Accepted Solutions
MxRowanP
5 - Automation Enthusiast
5 - Automation Enthusiast

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:

MxRowanP_1-1728939552440.png

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

See Solution in Thread

2 Replies 2
MxRowanP
5 - Automation Enthusiast
5 - Automation Enthusiast

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:

MxRowanP_1-1728939552440.png

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

nishant_tank
4 - Data Explorer
4 - Data Explorer

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")
}