Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Jira Automation rule Smart Value lookup of Custom Fields and Components to Labels

Sam Adams August 14, 2023

I am in need of an automation rule that (when true) runs the following json script that does smart value lookups for custom Field and Component fields in the ticket and adds them as Labels in the ticket.


I have the following for my JSON Body


{
"update": {
"labels": [
{
"add": "{{issue.fields.customfield_10041}}"
},
{
"add": "{{issue.components.name}}"
},
}
]
}
}

I tried this variant with no luck too

{
"update": {
"labels": [
{
"add": {
"id":"{{issue.fields.customfield_10041}}"
},
{
"add": {
"id":"{{issue.components.name}}"
},
}
]
}
}

 

I have no problem triggering the rule, just getting the JSON action to run successfully in looking up the values. I keep getting "Error while parsing additional fields. Not valid JSON." errors. I've run these same {{issue.etc}} lookup values in other types of rules and they return the expected values. So no issues with getting them to look up values else where (just with lables). Thanks2023-08-13_23-56-04.png

2 answers

1 accepted

2 votes
Answer accepted
Sayed Bares _ServiceRocket_
Community Champion
August 14, 2023

@Sam Adams welcome to the community!

There is a typo in your JSON, try the following and let me know if it works:

{
"update": {
"labels": [
{
"add": "{{issue.fields.customfield_10041}}"
},
{
"add": "{{issue.components.name}}"
}
]
}
}
Sayed Bares _ServiceRocket_
Community Champion
August 14, 2023

FYI the typo is in test.jpg

Sam Adams August 14, 2023

Hi @Sayed Bares _ServiceRocket_ , Thanks for the quick reply. I did indeed have a typo, thank you. 
Corrected things to
{
"update": {
"labels": [
{
"add": "{{issue.fields.customfield_10041}}"
},
{
"add": "{{issue.components.name}}"
}
]
}
}
That solved one issue....but opened another.
I am now getting a new error perhaps you may know too?
The error says "xxxxx (The label 'xxxxxxx' can't contain spaces. (labels))"? The value it returns to me for 'xxxxxxx' in the error is what I am expecting too btw (no spaces I see). Any help is appreciated thx

Sayed Bares _ServiceRocket_
Community Champion
August 14, 2023

@Sam Adams the error usually happens if  'xxxxxxx' has a space since labels can never have a value with a space and if your code adds one then the validation kicks in. Are you sure 'xxxxxxx' doesn't have a space? can you share a screenshot if you don't mind?

Sam Adams August 14, 2023

It does contain a backslash "value/value"....could that character be causing problems?

Sayed Bares _ServiceRocket_
Community Champion
August 14, 2023

@Sam Adams No, backslash wouldn't cause any issue

Sayed Bares _ServiceRocket_
Community Champion
August 14, 2023

You may want to try a replace function to get rid of any potential spaces from your code by adding .replace(" ", "") in the field which is causing the error. example:

{{issue.components.name.replace(" ", "")}}
Sam Adams August 14, 2023

Thank i'll try that. One last question while I have ya. When I try a value that does not contain spaces it gets returned successfully (Yeah!!!) ....however the label literally gets added with Quotes (example insted of just 'Account' for my label I get '"Account"' made as a label. Any way to trim the quotes of a newly made label? Last question :) thx 

Sam Adams August 14, 2023

Disregard the earlier question @Sayed Bares _ServiceRocket_ I worked now with no quotes. Thanks again for all your help

Johan Markström
Contributor
August 14, 2023

You could try using the asJsonString function and it should remove the quotation marks: 

{{issue.fields.customfield_10041.asJsonString}}
Sayed Bares _ServiceRocket_
Community Champion
August 14, 2023

You are most welcome @Sam Adams FYI that is possible with replace function {{issue.fields.summary.replace("\"", "")}} it will remove your quotes :)

0 votes
Johan Markström
Contributor
August 14, 2023

Hi @Sam Adams!

 

There seems to be a trailing curly bracket at the end of the "labels" array:

"labels": [
{
"add": "{{issue.fields.customfield_10041}}"
},
{
"add": "{{issue.components.name}}"
},
} <----
]

 

Try removing it and it should work! 

 

Regards,

 

Johan Markström

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events