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:
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
Hi @David Leal!
I think there's a few issues.
So I think what you want is:
{
"fields": {
{{#if(equals(userInputs.team, "TEST"))}}"customfield _10014": "DOPI-284"{{/}}
}
}
Let us know if that works!
@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:
Maybe I am missing something to understand how this mark works.
Thanks,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I see, no in my case the problem is with the # mark (I tested removing the braces and I got the error). For example:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
I think you can probably put that comma from the line above (after customfield_10103) before the customfield_10014.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.