Automations
All questions related to Workflow Automation, AutomationEngine, and EdgeConnect, as well as integrations with various tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Error evaluating custom condition. Undefined variables: list object has no element 0.

erh_inetum
Champion

Hi,

I've created a workflow for Dynatrace-Service Now integration.

On this step, it returns this error:

erh_inetum_0-1782899242499.png

But the previous step has State "Success"

erh_inetum_1-1782900054690.png

The condition of the step that is failing is this:

erh_inetum_2-1782900141116.png

Does anyone know why it's failing in spite of the previous step is returning Success and how to fix this?

 

Thanks in advance.

Regards,

Elena.

 

 

 

 

 

 

5 REPLIES 5

PacoPorro
Dynatrace Leader
Dynatrace Leader

Probably the search_incident step has State: Success but State info: null - meaning the search executed successfully but found no incidents (returned an empty result).

However, your comment_on_incident step's custom condition is trying to access:
{{ result("search_incident")[0].sys_id }}

This fails because there's no element at index [0] in an empty/null result, causing the error: "list object has no element 0"

 

You need to check if the search actually returned results before accessing the first element.
try to modify the custom condition to:

{{ result("search_incident") and len(result("search_incident")) > 0 and result("search_incident")[0].sys_id }}

Hi Paco,

Thanks you so much for your quick answer.

You're right. The State info is null. That's because it doesn´t find any incidents.

erh_inetum_0-1782903209065.png

I've put the condition you told me and it returns this:

Error evaluating custom condition. Undefined variables: len.

 

Thank you Paco!

Regards,

Elena.

 

 

Hi again Paco,

As I told you, this:

{{ result("search_incident") and len(result("search_incident")) > 0 and result("search_incident")[0].sys_id }}

returns Error.

But this:

{% if result("search_incident") and result("search_incident")|length > 0 %}
{{ result("search_incident")[0].sys_id }}
{% endif %}

returns results onces there is created incidents:

erh_inetum_0-1782908703542.png

I've run again the workflow and now the workflow ends successfully but it skips the two next steps:

erh_inetum_1-1782909056447.png

I think it’s working properly now and this behaviour it's normal. And if it's skipping the next following steps and doesn’t do anything else, I think it’s because the created incident hasn´t been any changes so far. And as no further issues have been creating in Problems, there’s nothing new for it to create either.

Thanks a lot for the clues.
Best Regards,
Elena.

{% if result("search_incident") and result("search_incident")|length > 0 %}
{{ result("search_incident")[0].sys_id }}
{% endif %}

You're right, my solution included python intead of jinja 😄 

So now, the behavior is working as intended:

 No incident found → Custom condition evaluates to false/empty
 "Run this task if" condition fails → Step is skipped
 Subsequent steps that depend on this one → Also skipped (cascading skip)

Hi Paco,

Thank you very much for confirming how the workflow behaves once the condition has been changed and it's correct and for the very detailed explanation of the steps.

Have a nice day.
Regards,
Elena.

Featured Posts