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). Thanks
@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}}"
}
]
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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(" ", "")}}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Disregard the earlier question @Sayed Bares _ServiceRocket_ I worked now with no quotes. Thanks again for all your help
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You could try using the asJsonString function and it should remove the quotation marks:
{{issue.fields.customfield_10041.asJsonString}}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You are most welcome @Sam Adams FYI that is possible with replace function {{issue.fields.summary.replace("\"", "")}} it will remove your quotes :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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.