Populating Labels Based on Assignee (Issue with parsing JSON)
Asked by Allison:

Hello,

I'm trying to build an automation to update the label with the assignee display name-HI when the assignee is changed. Since labels do not accept spaces, I need to use the advanced fields (<https://support.atlassian.com/jira-software-cloud/docs/advanced-field-editing-json/> and <https://confluence.atlassian.com/jirakb/automation-for-jira-fails-to-copy-components-list-to-label-with-error-message-the-label-contains-spaces-which-is-invalid-1072473388.html>) .

So, if I assignee an issue to a user named First Last, I'd like the label to be FirstLast-Hi

I have attempted dozens of configurations , but always get an error. I am hoping someone can assist in getting this to work:

{

"update": {

"labels": \[{

"add": "{{assignee.displayName.remove(" ").concat("-RH")}}"

}\]

}

}

Here's the error:

Error editing issues: (Field labels cannot appear in both 'fields' and 'update')

Thank you in advance!  
Allison


Answers:
author: Bill Sheboy
body: Hi [@Allison](/t5/user/viewprofilepage/user-id/4374987)

I noted that you have nested double-quoting in your update, due to formula usage. Have you tried to work around that by switching to single-quotes inside?

```
 "add": "{{assignee.displayName.remove(' ').concat('-RH')}}"
```

Or, you could save the right-side value to a created variable and then use that one.

Best regards,  
Bill

comments: author: Allison
body: Thank you for your reply, Bill!

I attempted to replace the double quotes with single quotes and still had the same result. (Field labels cannot appear in both 'fields' and 'update')

Taking the next step of your advice, I tried to remove the second value/calculation and had the same result.

It seems the syntax is correct, so I'm stumped! Thanks so much for the help!


author: Bill Sheboy
body: Fascinating...It appears that concat() will not work with single quotation marks.

So one workaround is to put this in a created variable and then set the labels to it:

{{issue.assignee.displayName.remove(" ").concat("-RH")}}

To set the labels to the smart value from the created variable (e.g. let's say we named it varAssigneeLabel

* select the edit issue action
* select the labels field
* type in the smart value {{varAssigneeLabel}}
* And then when it displays below the field, select that value
* Confirm that is what is now shown in the field value


author: Allison
body: Thanks Bill! Is this feature available in Jira Server? From what I see you posted on another article, it seems I may be out of luck on the workaround, too. <https://community.atlassian.com/t5/Jira-articles/Automation-for-Jira-Create-variable-New-component/ba-p/1448118>


author: Allison
body: I just figured it out!

The syntax of the first example was correct. The issue was that I had the labels set to be cleared (look under the cog icon)

![Screenshot from 2021-07-30 15-50-11.png](https://community.atlassian.com/t5/image/serverpage/image-id/153835i917E1828A630FF4B/image-size/large?v=v2&px=999 "Screenshot from 2021-07-30 15-50-11.png")

Once I removed the "this field will be cleared action" everything worked. I think the two settings were conflicting each other throwing it into a loop.  
![Screenshot from 2021-07-30 15-50-45.png](https://community.atlassian.com/t5/image/serverpage/image-id/153836iFA516C9D31A74EC2/image-size/large?v=v2&px=999 "Screenshot from 2021-07-30 15-50-45.png")

Thanks again for your help!


author: Bill Sheboy
body: Sorry about that! I noted the tagging which indicated you were using Cloud.

I just tried this and it worked for cloud, so you'll need to test for server: just do it directly without a variable or JSON edit...

Edit issue for the labels field, and paste that smart value expression in directly. When it shows beneath the field, and save. Then try the rule:

{{issue.assignee.displayName.remove(" ").concat("-RH")}}


author: Bill Sheboy
body: Ah, two edits of labels. If you noted above, you may also be able to do this without the advanced edit.


Tags: cloud