Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Using conditional {{Smart values}} in comment field fails for custom fields

Timon Karge-Lücker
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 24, 2024

Dear hive-mind, can you kindly help me on this issue?

Target situation:

  1. If someone has moved a ticket into refined, an automatic comment should notify this person (context).
  2. The comment should list N relevant fields that were not specified (left empty) (focus of this question).
  3. Only a single comment should state what is missing, to reduce spam (my current workaround spams multiple comments - not in focus here)

Approach: 

  1. Writing a general comment that only triggers, if at least one of the relevant values is empty using "If: any match" (works)
  2. Using conditional smart values to show -most Jira fields- (works)
    1. Results in: "Description is empty"
      1. {{#if(issue.description.isEmpty)}}
        Description is empty
        {{/}}
  3. - Using conditional smart values to show -any custom fields- (problems)
    1. Results for no value in field and value in field: nothing
      1. {{#if(issue.customfield_12934.isEmpty)}}
        Relevance is empty
        {{/}}
    2. Results for no value in field and value in field: "Relevance is empty"
      1. {{#if(not(issue.customfield_12934.isEmpty))}}
        Relevance is empty
        {{/}}
      2. {{#if(not(issue.customfield_12934))}}
        Relevance is empty
        {{/}}
  4. Using conditional smart values to show a -specific Jira field: Original Estimate- (errors)
    1. Assumptions
      1. The default value for {{issue.fields.timetracking.originalEstimateSeconds}} = 0
      2. Hence, is.Empty does not work here
    2. Results in: Error rendering smart-values when executing this rule
      1. {{#if(equals({{issue.fields.timetracking.originalEstimateSeconds}}, "0"))}}
        Original Estimate is empty
        {{/}}
    3. Results for no value in field and value in field: nothing
      1. {{#if({{issue.fields.timetracking.originalEstimateSeconds.lt(1))}}
        Original Estimate is empty
        {{/}}
      2. same for .gt(0) instead of .lt(1)
    4. Results for no value in field and value in field: "Original Estimate is empty"
      1. {{#if(not({{issue.fields.timetracking.originalEstimateSeconds.lt(1)))}}
        Original Estimate is empty
        {{/}}
      2. same for .gt(0) instead of .lt(1)

 

Thank you most kindly!
Timon

1 answer

1 vote
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.
April 24, 2024

Hi @Timon Karge-Lücker -- Welcome to the Atlassian Community!

Sorry for the long answer, as I have also spent lots of time on this automation behavior of determining emptiness.  I will add bolded text to help focus the ideas I suggest.

 

First thing, are you using Jira Cloud, Server, or Data Center version, as automation rule behavior is different for the different app versions?  Your post seems to indicate Cloud, but that linked documentation you noted is for Server / Data Center.  Here is the one for Jira Cloud automation: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/#isEmpty--

The isEmpty() function works for text fields, and few others.  Additionally, I have found testing for "empty" or "blank" to vary in behavior based upon field types.  Experimentation is often required to determine what will work for testing values with isEmpty() and other methods.  Note that distinction I made between "empty" and "blank", where one is a null value and one is a zero-length string.  And so things like conditional expressions could collapse when a smart value is null, leading to no result, true, false, or otherwise: it is just null.

Some fields, once set to a value and then later cleared, appear to never be null again: they are instead "blank" or in some other state.  The workaround for this is to concatenate to a known value, remove that value, and then test the length of the resulting text for zero.

Context is important for automation rules.  You do not show your rule(s), and it may be possible that some fields are empty because the smart value, or issue, does not exist at that rule scope.  Writing to the audit log can help to confirm this.

Without seeing your rule, I cannot tell if you are using any iterators or list fields (e.g., Sprint, multiple select option, etc.).  Inside of an iterator, the community has observed symptoms of conditional logic errors for list fields, where the wrong values are returned.  The workaround for that is to fully expand the iterator and list values into a created variable first, and then use either conditional logic or the match() function.

For your specific examples shown, I see some extra curly brackets inside of the conditions, such as the one below.  Try removing the extra brackets once inside of the conditional logic.

{{#if(equals({{issue.fields.timetracking.originalEstimateSeconds}}, "0"))}}
Original Estimate is empty
{{/}}

Finally, the values for some smart values appear to be dynamically determined by additional REST API calls.  (For example, the content of subtasks.)  These may also collapse to null when used with functions, particularly withing conditional logic expressions.  My recommendation is when something that looks like it should work does not work, save the field to a created variable first and then try the condition.

Kind regards,
Bill

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events