Hi,
I'm I'm trying to remove specific characters '[', ']', and '"' (quotation marks) from a 'value' in the description. Below is the value.
Additional Hardware Selected: ["laptop dock", "laptop", "keyboard", "mouse"]
I'm first using create variable function in an automation to create a variable with the name {{msformAddHardware}} and the value {{issue.description.match("Additional Hardware Selected: *(.*)")}}.
Then, I'm using the Audit Log function with the smart-value {{msformAddHardware.replaceAll("[\\[\\]\"]", "")}} but the Audit log shows the log function is empty.
My purpose for this is, in the automation, to use the created variable to set the value for a multi-select custom field.
Please help. Thanks!
Hi John,
I know that character Classes work for replaceAll().
If you are getting this "[\\[\\]\"]" (isn`t there an extra " ?) from different parts of the text,
try chainning the characters, for example:
{{issue.summary.replaceAll("[\\]", "").replaceAll("\", "")}}
and so on. Start with the first character, test, and then progress adding the others.
Hi, William
The Log Action was returning the error below.
Failed to get value for msformAddHardware.replaceall("[\\]", ""): {{msformAddHardware.replaceall("[\\]", "")}}
I ended up using: value {{msformAddHardware.replaceAll("[\\[\\]\"]", "")}} to create a new variable "addHard". Then, created a new variable "selectHardware" with the value {{addHard.trim()}}.
I might have over done it with all the created variables but nonetheless.
Then, with in the "Edit" function I used the following JSON.
{
"fields": {
"customfield_12487": [
{{#selectHardware.split(",")}}
{"value": "{{.}}"}{{^last}},{{/last}}
{{/}}
]
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @John Izquierdo
Yes, as @William Calesco has mentioned, try chaining the "replace" function to replace one at a time.
Once you have a clean list separated by commas in your variable (which is still text), please check the method demonstrated by @Bill Sheboy in below post on how to format your text to JSON so you can set/update your field accordingly.
https://community.atlassian.com/t5/Automation-questions/Converting-list-to-JSON-object/qaq-p/2551363
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks, Kalyan!
I was still confused reading that post (still kind of new to Jira and getting familiar with smart-values but don't know a lick of JSON), thankfully we're working with some devs from OnRamp who provided the same solution and was able to explain it/how it works.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, It takes a couple of tries to absorb how to iterate a list and format the JSON to get it so you can update corresponding fields.
And that method of @Bill Sheboy is one of my absolute favorites I have ever seen. Its just such a simple yet, out of the box solution that my mind was blown away and i am still impressed, lol.
For reference, if you look at below Jira KB article on "how else" it could have been achieved, its just confusing and feels round about. That's what i admire about that solution.
BTW, can I please ask you to accept @William Calesco answer as well, his solution was the correct one so folks researching in the future can benefit by quickly getting to the answer. Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah! I might have been thinking of a different community post with a similar question to mine. I didn't try, but still don't fully understand the article you linked, I'll have to stare at it for a while and test it out and fail a couple of time. lol
I explained what method I ended up using in a reply to @William Calesco... I might have used the roundabout way of doing it tbh.
Once I figure out and successfully use the method provided in that article I will be sure to update my automation so it doesn't feel like a mess.
Thanks again!
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.