Why won't this conditional logic work? {{#if(customfield_12038.value("Constituents"))}}

Emily Perridge November 14, 2023
Why won't this conditional logic work?
{{#if(customfield_12038.value("Constituents"))}} Data requirement is constituents.{{/}}
I am trying to make a Jira automation using if-then blocks. The automation is run manually from an "action" on a Jira issue in a Jira project. Within the automation I have an "if" block, which checks if the mandatory custom fields are populated. If any of these mandatory fields have no value, an email is sent to the automation initiator. In this email, I want to tell the automation initiator what changes they need to make (to the Jira issue) for the automation to run successfully - the email does this using conditional logic and smart values.
This automation works fine when "isEmpty" is used with the smartvalue. However, the automation doesn't work when I ask it to check a specific string.
In pseudocode, what I want to achieve is:
if customfield_12038 = "constituents" and customfield_12808 is empty

      print("Data requirement is constituents, you must enter a data type")
Where data requirement = customfield_12038 and data type = customfield_12808
The first step is getting "if customfield_12038 = "constituents"". After this, I can get the and condition to work.
Below are all the different combinations of smart values and conditional logic I've tested. As I explained, you see the logic works when I use "isEmpty" but not when I specify a value. I'll be using is [customfield_12038 = Constituents] but I tested with another field (data partner/customfield_12589).

Conditional Logic

Output when true

Output when false

Notes

(6) Checking field: Data Requirement
{{#if(equals(customfield_12038, isEmpty))}}
Data requirement is empty. Please add a value.
{{/}}

Data requirement is empty. Please add a value.

 

:white_check_mark:

(6) Checking field: Data Requirement

{{#if(not(equals(customfield_12038, isEmpty)))}}
Data requirement is not empty. Value = "{{customfield_12038.value}}"
No action is required on this field. If data requirement = "constituents", please ensure data type has a value.{{/}}

 

Data requirement is not empty. Value = Constituents

No action is required on this field. If data requirement = "constituents", please ensure data type has a value.

:white_check_mark:

(7) Checking field: Data Type
{{#if(equals(customfield_12808, isEmpty))}}
Data type is empty. Please add a value if data requirement = "constituents".
{{/}}

Data type is empty. Please add a value if data requirement = "constituents".

 

:white_check_mark:

(7) Checking field: Data Type

{{#if(not(equals(customfield_12808, isEmpty)))}}
Data type is not empty. Value = "{{customfield_12808.value}}". No action is required.
{{/}}

 

Data type is not empty. Value = Open. No action is required.

:white_check_mark:

TEST A - CONS

{{#if(not(customfield_12038.value("Constituents")))}} Data requirement is not Constituents. No action is required. {{/}}

TEST A - CONS
Data requirement is not Constituents. No action is required.

TEST A - CONS
Data requirement is not Constituents. No action is required.

:cross_mark:Same output when

customfield_12038 = Constituents

and when

customfield_12038 != Constituents

TEST A - PARTNER

{{#if(not(customfield_12589.value("DP-TEST")))}} Data partner is not DP-TEST. No action is required. {{/}}

TEST A - PARTNER
Data partner is not DP-TEST. No action is required.

TEST A - PARTNER
Data partner is not DP-TEST. No action is required.

:cross_mark:customfield_12589 = DP-TEST, but automation says it isn’t

Same output when

customfield_12589 = DP-TEST

and when

customfield_12589 != DP-TEST

TEST B - PARTNER EMPTY

{{#if(equals(issue.customfield_12589, "None"))}}

Data partner is empty. Please add the data partner{{/}}

TEST B - PARTNER EMPTY

TEST B - PARTNER EMPTY

:cross_mark:customfield_12589 = DP-TEST, but automation says it isn’t

Same output when

customfield_12589 = DP-TEST

and when

customfield_12589 != DP-TEST

TEST B - PARTNER NOT EMPTY

{{#if(equals(issue.customfield_12589, "DP-TEST"))}}

Data partner is not empty. Value = "{{customfield_12589.value}}"{{/}}

TEST B - PARTNER NOT EMPTY

TEST B - PARTNER NOT EMPTY

:cross_mark:Same output when

customfield_12589 = DP-TEST

and when

customfield_12589 != DP-TEST

TEST C – CONS STRING

{{#if(customfield_12038("Constituents"))}}

Data requirement is constituents. {{/}}

TEST C – CONS STRING

TEST C – CONS STRING

:cross_mark:Same output when

customfield_12038 = Constituents

and when

customfield_12038 != Constituents

TEST C – PART STRING

{{#if(customfield_12589 ("DP-TEST"))}} Data partner is DP-AAM. {{/}}

TEST C – PART STRING

TEST C – PART STRING

:cross_mark:customfield_12589 = DP-TEST, but automation says it isn’t

Same output when

customfield_12589 = DP-TEST

and when

customfield_12589 != DP-TEST

TEST D – PARTNER VALUE STRING

{{#if(customfield_12589.value("DP-TEST"))}} Data partner is DP-AAM. {{/}}

TEST D – PARTNER VALUE STRING

TEST D – PARTNER VALUE STRING

:cross_mark:customfield_12589 = DP-TEST, but automation says it isn’t

Same output when

customfield_12589 = DP-TEST

and when

customfield_12589 != DP-TEST

TEST D – CONS VALUE STRING

{{#if(customfield_12038.value("Constituents"))}}

Data requirement is constituents.{{/}}

TEST D – CONS VALUE STRING

TEST D – CONS VALUE STRING

:cross_mark:Same output when

customfield_12038 = Constituents

and when

customfield_12038 != Constituents

1 answer

0 votes
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 14, 2023

Hi @Emily Perridge 

Thanks for the details in your question, and well done on methodically working through the cases!  Problems in automation rules are often about context, so please consider also posting images of the complete rule and audit log details showing the rule execution.

Without seeing those...

isEmpty() is a function, and not a value; the documentation says it returns true or false and cannot be compared to as you are doing: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/#isEmpty--

 

To test for null or "no value" you could use {{#if(customfield_12038.value)}}has no value{{/}}
To test for "empty string" you could use {{#if(customfield_12038.value.isEmpty())}}has no value{{/}}

However I have observed that not consistently working, so try it to compare to your results.  Some Jira fields, even when never set, contain either null (no value) or empty string.  Those are not the same thing when testing conditions.  Worse still, once some fields are set and later cleared, they do not return to the original null value.  Again, please test to confirm.

 

To test for a specific value, please try the equals() function in your condition:

{{#if(equals(customfield_12038.value, "Constituents"))}} Data requirement is constituents.{{/}}

 

Kind regards,
Bill

Emily Perridge November 17, 2023

Hi Bill,

Thank you for your contribution - it's much appreciated!

Regarding testing for a specific value, I tried:

When: Manually triggered

If: matches
Data Requirement contains: Constituents

Then: Send email
To - Initiator
Subject - Action required on {{issue.key}}
Content -
{{#if(equals(customfield_12038.value,"Constituents"))}}
Data requirement is constituents.{{/}} 

As expected, when I ran the automation an email was send because data requirement = constituents. However, the email had no content. I was expecting the email to contain the message "Data requirement is constituents".

(I tried adding a screenshot of the automation rules, but I wasn't able to due to the error "Permission Denied".)

Best regards,

Emily

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 17, 2023

That is an curious message for trying to add the image.  Did you see that using the Insert Photos option for your post?

Capture.PNG

 

What is the type of your "Data Requirement" field: single-select option, multiple-select option, or something else?

 

For the options in the custom field configuration, have you confirmed:

  • there are no leading / trailing spaces, and
  • the case matches exactly what you are comparing to?

Either one of those could also cause a mismatch.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events