Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Populating Labels Based on Assignee (Issue with parsing JSON)

Allison
Contributor
July 30, 2021

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

1 answer

1 vote
Bill Sheboy
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.
July 30, 2021

Hi @Allison 

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

Allison
Contributor
July 30, 2021

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!

Bill Sheboy
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.
July 30, 2021

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
Allison
Contributor
July 30, 2021

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

Allison
Contributor
July 30, 2021

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

 

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

 

 

Thanks again for your help!

Like # people like this
Bill Sheboy
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.
July 30, 2021

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")}}

Bill Sheboy
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.
July 30, 2021

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events