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

**URL:** <https://community.dynatrace.com/t/error-evaluating-custom-condition-undefined-variables-list-object-has-no-element-0/56340>\
**Category:** Automations\
**Tags:** integrations, workflows, automations, servicenow\
**Created:** [July 1, 2026, 10:13am UTC](https://community.dynatrace.com/t/error-evaluating-custom-condition-undefined-variables-list-object-has-no-element-0/56340 "2026-07-01T10:13:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![erh\_inetum](https://avatars.discourse-cdn.com/v4/letter/e/48db29/32.png) [@erh\_inetum](https://community.dynatrace.com/u/erh_inetum)\
**Post date:** [July 1, 2026, 10:13am UTC](https://community.dynatrace.com/t/error-evaluating-custom-condition-undefined-variables-list-object-has-no-element-0/56340/1 "2026-07-01T10:13:12Z")

</div>

Hi,

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

On this step, it returns this error:

 ![erh_inetum_0-1782899242499.png](https://global.discourse-cdn.com/dynatrace/original/2X/3/3bfd62a1d214d06e3c51f90d11742727016a790d.png)

But the previous step has State “Success”

 ![erh_inetum_1-1782900054690.png](https://global.discourse-cdn.com/dynatrace/original/3X/b/5/b5460d9248f31a3e8c39c58382e5b3932e215ad1.png)

The condition of the step that is failing is this:

 ![erh_inetum_2-1782900141116.png](https://global.discourse-cdn.com/dynatrace/original/2X/1/1f04663503b89524dd458a6dadd379ddad51bd67.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.

---

<div class="post-metadata">

**Author:** ![PacoPorro](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/pacoporro/32/36087_2.png) [@PacoPorro](https://community.dynatrace.com/u/PacoPorro)\
**Post date:** [July 1, 2026, 10:21am UTC](https://community.dynatrace.com/t/error-evaluating-custom-condition-undefined-variables-list-object-has-no-element-0/56340/2 "2026-07-01T10:21:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![erh\_inetum](https://avatars.discourse-cdn.com/v4/letter/e/48db29/32.png) [@erh\_inetum](https://community.dynatrace.com/u/erh_inetum)\
**Post date:** [July 1, 2026, 11:58am UTC](https://community.dynatrace.com/t/error-evaluating-custom-condition-undefined-variables-list-object-has-no-element-0/56340/3 "2026-07-01T11:58:43Z")

</div>

Hi Paco,

Thanks you so much for your quick answer.

You’re right. The&nbsp;State info is null. That’s because it doesn´t find any incidents.

 ![erh_inetum_0-1782903209065.png](https://global.discourse-cdn.com/dynatrace/original/2X/2/265b47fdb8ff0c43bff5b601f61a9f2480851930.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.

---

<div class="post-metadata">

**Author:** ![erh\_inetum](https://avatars.discourse-cdn.com/v4/letter/e/48db29/32.png) [@erh\_inetum](https://community.dynatrace.com/u/erh_inetum)\
**Post date:** [July 1, 2026, 12:38pm UTC](https://community.dynatrace.com/t/error-evaluating-custom-condition-undefined-variables-list-object-has-no-element-0/56340/4 "2026-07-01T12:38:00Z")

</div>

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](https://global.discourse-cdn.com/dynatrace/original/3X/5/8/583c8c4d81b2dced0a7da274b6d200a1050e341e.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](https://global.discourse-cdn.com/dynatrace/original/3X/4/9/49864249cd76512631a15d8145062d979961a39b.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.

---

<div class="post-metadata">

**Author:** ![PacoPorro](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/pacoporro/32/36087_2.png) [@PacoPorro](https://community.dynatrace.com/u/PacoPorro)\
**Post date:** [July 1, 2026, 2:07pm UTC](https://community.dynatrace.com/t/error-evaluating-custom-condition-undefined-variables-list-object-has-no-element-0/56340/5 "2026-07-01T14:07:59Z")

</div>

{% 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  
&nbsp;“Run this task if” condition fails → Step is skipped  
&nbsp;Subsequent steps that depend on this one → Also skipped (cascading skip)

---

<div class="post-metadata">

**Author:** ![erh\_inetum](https://avatars.discourse-cdn.com/v4/letter/e/48db29/32.png) [@erh\_inetum](https://community.dynatrace.com/u/erh_inetum)\
**Post date:** [July 2, 2026, 5:08am UTC](https://community.dynatrace.com/t/error-evaluating-custom-condition-undefined-variables-list-object-has-no-element-0/56340/6 "2026-07-02T05:08:34Z")

</div>

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.
