Hi,
Is there a way to convert a list of values to JSON?
I have a multi-select custom field multi_field with these options:
In a group of issues, options 2+4+5 were chosen, for instance. I want to clone the issues using an automation rule, but to change the chosen options to be all with the suffix 123. meaning:
2: ABC 456 => ABC 123
4: DEF 456 => DEF 123
5: no change
I thought doing so with this smartvalue:
{
"fields": {
"multi_field": "{{issue.fields.multi_field.replace("456","123")}}"
}
}
but this phrase returns a string ABC 123, DEF 123, GHI 123
while I need to retrieve a JSON object (according to the documentation) like:
[{"value": "ABC 123"}, {"value": "DEF 123"}, {"value": "GHI 123"}]
I tried using the asJsonStringArray & asJsonObjectArray functions but it didn't work for me.
Does someone have an idea how to solve this problem, maybe in a different way completely?
Thanks in advance
Have you tried using the JSON array function first, and then performing the replacement of text on the result, and finally use that to set the field in the advanced edit?
If that does not work, you could also try to construct the JSON string using a list iterator over the source field, replacing the text for each one.
Kind regards,
Bill
Thanks @Bill Sheboy!
I used your first idea and it worked!
I didn't find a way to use iterations in the JSON advanced options
(for instance using {{#issue.comments}}...{{/}})
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am glad to learn that helped!
For the second method, I was suggesting something like this to dynamically build the right-side of the JSON...although I have not tried it:
[ {{#issue.fields.multi_field}} { "value" : \"{{value.replace("456","123")}}\" } {{^last}},{{/}}{{/}} ]
I have successfully done this with other functions, but not with replace(), so the extra quotation marks could be a problem.
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.