Advanced field editing using smart values conditional logic

David Leal
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.
August 28, 2023

I am using Advanced field editing using JSON with the following JSON file:

{
"fields": {
{{if(equals({{userInputs.team}}, "TEST"))}}"customfield_10014" : "DOPI-284"{{/}}
}
}

I have defined a smart value {{userInputs.team}} and I want to assign the custom field (epic link): "customfield_10014" to a given epic key only if the smart value is equal to "TEST". I am getting the following error:

Screenshot 2023-08-28 at 10.47.41 PM.png

I tried several options, but I am getting the same error message, it seems Advanced field editing using JSON doesn't allow Jira smart value - conditional logic. It accepts smart values, but such conditional functions related to the smart values.

Is correct my assessment or am I doing something wrong? Is there any feature request to allow it?

The workaround would be to implement such if condition as part of the automation rule workflow, but it results in a verbose rule.

Thanks,

David

1 answer

1 accepted

1 vote
Answer accepted
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.
August 28, 2023

Hi @David Leal!

I think there's a few issues.

  • You're missing a # mark before the if
  • You don't need to put userInputs.team in {{braces}} because you're already inside of a function that works with Smart values.

So I think what you want is:

{
"fields": {
{{#if(equals(userInputs.team, "TEST"))}}"customfield _10014": "DOPI-284"{{/}}
}
}

Let us know if that works!

David Leal
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.
August 29, 2023

@Darryl Lee it works I have tested removing the braces, but not adding # mark. I didn't add it, because in the user.Inputs I have several values, but the user selects just one, so it has a single value. My understanding is that this mark is for iterating over several values. In the documentation: Jira smart value - conditional logic there are examples for a single value and multiple values such as:

{{if(equals(issue.assignee, issue.reporter))}} 
Assign this issue to someone else so they can review.
{{/}}

and multiple values:

{{#if(not(issue.issuelinks.isEmpty))}} 
This bug has {{issue.issuelinks.size}} related tickets
{{/}}

For example, in another section of my rule, I use the following and it works:

Screenshot 2023-08-29 at 8.51.33 AM.png

Maybe I am missing something to understand how this mark works.

Thanks,

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.
August 29, 2023

Ah, yeah, it's weird how sometimes the documentation shows if with a # and other times it does not (even outside of the list context), like here for the exists function:

{{#if(exists(issue.designer))}}
The designer for this issue is {{issue.designer.displayName}}
{{/}}

But yeah, then I guess the real problem in your case was putting braces around the smart value when you were in the if clause.

Yes, when used by itself, a smart value require braces.

But you're using it as part of a function that is already in braces, so that's why you don't need an additional set of braces around the variable, "userInputs.team". Again, the example for exists shows that, as does your example for equals.

Like # people like this
David Leal
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.
August 29, 2023

I see, no in my case the problem is with the # mark (I tested removing the braces and I got the error). For example:

Screenshot 2023-08-29 at 1.09.28 PM.png

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.
August 29, 2023

So what finally worked? Adding the # and removing braces, per my example?

OH, if it is still not working, I see another issue. You end up with an extra comma if the TEST fails.

think you can probably put that comma from the line above (after customfield_10103) before the customfield_10014.

David Leal
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.
August 29, 2023

@Darryl Lee yes, what worked is your solution for example (adding # mark and removing the braces for userInputs.team):

{
"fields": {
"customfield_10100" : { "id": "{{severity.get(issue.customfield_10262.id)}}"},
"customfield_10101" : { "id": "{{type.get(issue.customfield_10264.id)}}"},
"customfield_10103" : { "id": "{{environment.get(issue.customfield_10266.id)}}"},
{{#if(equals(userInputs.team, "TEST"))}}"customfield _10014" : "DOPI-284"{{/}}
}
}

I don't see the extra comma you mentioned. The above code doesn't produce any error. My understanding is that if userInputs.team is not equal to "TEST" nothing is returned (or an empty line) to the JSON file. I would say Jira automation processes the JSON file first resolving the smart values/function, and then processing the final JSON file.

 

Thanks,

 

David

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.
August 29, 2023

Glad it is working! By extra comma, I meant that if your test for TEST fails, then the last element in fields before the closing braces would look like:

    "customfield_10103" : { "id": "{{environment.get(issue.customfield_10266.id)}}"},
}
}

And so there's that extra trailing comma.

But I guess Automation doesn't mind that. Cool.

Like David Leal likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events