Smart value - Return simple text if field does not have value
Asked by Kelvin Teng:

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.


Answers:
author: Jeroen Poismans
body: 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](https://community.atlassian.com/t5/image/serverpage/image-id/316492i821A5499CF6E7410/image-dimensions/271x199?v=v2 "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](https://community.atlassian.com/t5/image/serverpage/image-id/316493iC24FAA9B8442DC7C/image-dimensions/236x161?v=v2 "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


author: Kelvin Teng
body: Thank you everyone for the guidance. Managed to get it to work now.


author: Bill Sheboy
body: Hi [@Kelvin Teng](/t5/user/viewprofilepage/user-id/5469702) -- 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](https://support.atlassian.com/cloud-automation/docs/find-the-smart-value-for-a-field/) 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


author: Darryl Lee
body: Hi [@Kelvin Teng](/t5/user/viewprofilepage/user-id/5469702) - I believe this should do the trick:

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

comments: author: Darryl Lee
body: Ha! I had a similar answer to [@Jeroen Poismans](/t5/user/viewprofilepage/user-id/1708479) :-}