Hi,
Im trying to use If logic on a custom field.
{{#if(issue.customfield_18021.isEmpty)}}, issue.created.diff(now).businessDays , issue.created.diff(issue.customfield_18021).businessDays {{/}}
The goal is if customfield_18021 is empty date diff will use now and if there is a date (really not null) in customfield_18021 it does a datediff off of that.
Now this does work if i use if else blocks in jira automation but im trying to do reduce component usage by doing it in the varible.
When I run the code I get the correct answer from the if/else components but the above inline smart value returns null.
@Bill Sheboy tagging you incase you have insight (its def been appreciated in the past)
First, your syntax is not quite correct for that version of if: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-conditional-logic/#if
{{if(smartValue, "value if true", "value if false")}}
Yet even with that adjustment, it will not work due to the null value collapsing the expression.
In my experience with rules, one must experiment a bit with the different field types to detect the differences between null, has a value, and empty (i.e., had a value, was cleared, and can never be null again).
Date / time fields are essentially numbers, and they can be null or have a value. But there does not appear to be a built-in function for detecting null for them. The normal "exists" ones for inline conditionals do not appear to work. And so in the conditional you tried, everything collapses as soon as it hits the null.
One possible workaround is to start with a known, non-null value:
{{if(varNull.concat(issue.customfield_18021.jiraDate).equals("Null"),issue.created.diff(now).businessDays, issue.created.diff(issue.customfield_18021).businessDays)}}
That works by trying to concatenate the formatted date onto the variable and then testing the result. If the date is null, the parameter to the concat() collapses, but the equals() still works.
There may be a more elegant way to do this, but I haven't found it yet.
Kind regards,
Bill
Thank you this worked perfectly, I had tried it a few times with the regular expression you listed but exactly as you described it would not work and spit out some crazy stuff. Even if i assigned the field to a variable first.
This still saves 2 components on my end which is much appreciated!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Awesome; I am glad to learn that helped.
To make the rule logic clearer to someone reading it later, it may help to rename the variable to varNull and the test value to "Null". I will update my earlier post to match that.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.