Advanced field editing using smart values conditional logic
Asked by David Leal:

I am using [Advanced field editing using JSON](https://support.atlassian.com/cloud-automation/docs/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](https://community.atlassian.com/t5/image/serverpage/image-id/277667iE25AD7CB89F5CE49/image-size/large?v=v2&px=999 "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 J[ira smart value - conditional logic.](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-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


Answers:
author: Darryl Lee
body: Hi [@David Leal](/t5/user/viewprofilepage/user-id/1567948)!

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!

comments: author: David Leal
body: [@Darryl Lee](/t5/user/viewprofilepage/user-id/1365322) 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: J[ira smart value - conditional logic](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-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](https://community.atlassian.com/t5/image/serverpage/image-id/277739i0FD8C3FCFF371E57/image-size/large?v=v2&px=999 "Screenshot 2023-08-29 at 8.51.33 AM.png")

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

Thanks,


author: Darryl Lee
body: 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](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-conditional-logic/#exists):

```
`{{#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**.


author: David Leal
body: 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](https://community.atlassian.com/t5/image/serverpage/image-id/277824i8DE84DB25B2A5453/image-size/large?v=v2&px=999 "Screenshot 2023-08-29 at 1.09.28 PM.png")


author: Darryl Lee
body: 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.


author: David Leal
body: [@Darryl Lee](/t5/user/viewprofilepage/user-id/1365322) 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


author: Darryl Lee
body: 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.