Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Smart value - Return simple text if field does not have value

Kelvin Teng April 4, 2024

I am trying to create an automation rule to comment on issue when an issue is transitioned to Done status. In the comment, automation will post the following:

TextField_A: <Value_1>

TextField_B: <Value_2>

TextField_C: <Value_3>

However, in TexField_C it does not always have a value so I would like it to specify it as None instead of blank -> TestField_C:

May I know how do I achieve this?

I've tried using the following smart values and couldn't get it to work:

{{issue.customfield_ID.value.replace("null","None")}}

{{issue.customfield_ID.replace("null","None")}}

{{issue.customfield_ID.value.replace(" ","None")}}

{{issue.customfield_ID.replace(" ","None")}}

 

Thanks.

4 answers

1 accepted

0 votes
Answer accepted
Jeroen Poismans
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 4, 2024

Hi and welcome to the Atlassian Community!

You could try and solve this with a variable an SmartValue with condition:

Screenshot 2024-04-05 at 07.59.57.png

The variable creation looks like this:

{{if(exists(issue.TextField_C),issue.TextField_C, "None")}}

And in the UI:

Screenshot 2024-04-05 at 08.03.21.png

In the last step I logged out the value of the variable and saw it behaved as you would expect.

Give it a try!

Jeroen

0 votes
Kelvin Teng April 7, 2024

Thank you everyone for the guidance. Managed to get it to work now.

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.
April 5, 2024

Hi @Kelvin Teng -- Welcome to the Atlassian Community!

In addition to the other answers provided...

For automation rules, at least three things impact how to supply a value when the field is considered empty:

  1. what is the state of the issue, such as immediately after issue-created / cloned
  2. the field type, such as text, value selection, user selection, etc.
  3. has the field ever had a value previously

For the first one, newly created issues may reach rules in an unstable state due to racetrack errors, leading the entire field / smart value to be missing.  The symptom for this is often a rule error indicating the field is not present for the issue type.  The fix for that is to use the Re-fetch Issue action after the rule trigger and before performing the empty field check.

Next, the field type impacts the technique needed, because the exist() function does not work for all types.  Understanding how the fields are stored in the smart values helps to learn how to test for empty values for each type.  This is particularly tricky for nested structures, such as the Fix Version, Sprint, and similar fields.

Lastly, some field types, once ever set with a value, appear to have an "empty string" versus "null", and exists() only tests for null.  I recall defects logged for this symptom, and potential work-arounds are noted below.

 

Additional checks / workarounds are:

  • use the changelog {{fromString}} compared to an empty string,
  • concatenate a known value string to the field and test for that, or
  • just try using the default value operator pipe |, such as with {{issue.Story points|0}}

 

Kind regards,
Bill

0 votes
Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 4, 2024

Hi @Kelvin Teng - I believe this should do the trick:

TextField_C: {{#if(not(exists(issue.customfield_ID)))}}None{{/}}{{issue.customfield_ID}}

Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 4, 2024

Ha! I had a similar answer to @Jeroen Poismans :-}

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events