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.
I've got a similar issue happening:
I#m trying to update fields of an issue created within the automation in a project different from the trigger issue:
{
"update": { {{#if(exists(triggerIssue.customfield_11654))}}"components" : "Media"{{/}},
{{#if(exists(triggerIssue.customfield_11653))}}"components" : "Handling"{{/}},
{{#if(exists(triggerIssue.customfield_11875))}}"components" : "Reporting"{{/}},
{{#if(exists(triggerIssue.customfield_11874))}}"components" : "Consulting"{{/}},
{{#if(exists(triggerIssue.customfield_11671))}}"components" : "Ad-Hosting"{{/}},
{{#if(exists(triggerIssue.customfield_11650))}}"components" : "Creatives"{{/}}
},
}
any ideas what akes the JSON invalid (that's the error I get in the log)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Your best bet is to output your code into the audit log to debug what's happening.
You can simply copy/paste the entire "Custom data" blob into the Add value to the audit log action (yup, since Atlassian doesn't allow multilines, the "Log message" gets collapsed into a single long line with funny spacing.)
When you run the rule, you should have something that you can then copy/paste into a JSON validator like say, https://jsonlint.com/ or open up in a editor that is JSON Schema compatible, or if you're a glutton like me, try to format the JSON using jq and then puzzle over any errors it throws.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
ok, got it
my condition {{#if(exists creates , , in the Json if I have a given field empty
any idea how to handle that?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah, I think the issue that Fields always exist. I think you're trying to check if the fields are not empty?
Can you tell us what kind of fields those various Custom Fields are?
You might have success with:
{{#if(triggerIssue.customfield_11654.isNotEmpty))}}
However what you get back from isNotEmpty (and isEmpty) can be inconsistent, specifically when it comes to different field types, per @Bill Sheboy.
As always, if you see weirdness, I'd start putting breaking up your various field checks into separate Audit Log lines like:
MEDIA: {{#if(triggerIssue.customfield_11654.isNotEmpty))}}TRUE{{/}}
So you can see where things are working or failing.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It's interesting that Atlassian offers isNotEmpty for text fields, but NOT for fields that would generate a list.
Also, I've had occasional success with {{#if(listfield.size > 0)}}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
yes @Darryl Lee , I think you are correct about the validation approach, also figured.
in the meanwhlie , also not sure if I can cause such multiple updates for components in this manner.
Any advice how to put in a condition {{#if(triggerIssue.customfield_11654.isNotEmpty))}} inside a nested definition of component?
aka "components" : [ { "name" : "Media"} ]
what if it's multiple with each own condition?
aka "components" : [ { "name" : "Media"} ], [ { "name" : "Handling"} ] ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
custom fields just have numeric values to them
so what I want to achieve in the advanced editing (when issue is being created in a separate project through branching) - if a trigger issue field has a value in it - and additional component would be added when the issue in another project is created
if triggerIssue.customfield_11654 is not empty - Media component added to the end issue when created
if triggerIssue.customfield_11653 is not empty - Handling component also added
if triggerIssue.customfield_11875 - Reporting component also added and so on
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Darryl Lee
For the conditional logic with list presence, please try the inline version of gt() function:
{{#if(listField.size.gt(0)}} do something {{/}}
And also for @Dmitry Alabyan ...
In my experience, the advanced edit with JSON can have timing / parsing order problems. It is better to first build the JSON and store it with a Created Variable, perhaps named varJson, and then used that in the advanced edit: {{varJson}} That also helps for logging it to check the value is well-formed JSON.
Kind regards,
Bill
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah, so yeah, I think numeric fields will probably be treated like text?
I would try:
{
"fields": {
"components" : [
{{#if(triggerIssue.customfield_11654.isNotEmpty)}}{ "name" : "Media" }, {{/}}
{{#if(triggerIssue.customfield_11653.isNotEmpty)}}{ "name" : "Handling" }, {{/}}
{{#if(triggerIssue.customfield_11875.isNotEmpty)}}{ "name" : "Reporting" }, {{/}}
{{#if(triggerIssue.customfield_11874).isNotEmpty}}{ "name" : "Consulting" }, {{/}}
{{#if(triggerIssue.customfield_11671).isNotEmpty}}{ "name" : "Ad-Hosting }, {{/}}
{{#if(triggerIssue.customfield_11650).isNotEmpty}}{ "name" : "Creatives" }, {{/}}
]
}
}
Hopefully Automation is still lenient about trailing commas.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The automation advanced edit with JSON is not lenient on trailing commas. This is another good reason to build incremental elements in variables and then cleanup before using in the Edit Issue action.
Regarding numbers and isEmpty(), they are not text...and numbers in rules are also subject to the fuzziness of is it a number value yet or not (when first set versus updated versus cleared later).
I advise belt-suspenders-and-rope: if the value can never be zero, test for that. Otherwise format() it as text and then test with isNotEmpty().
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.