I have a variable (mylist) with list such as 50810, 50811 which is populated from a web request.
I was able to convert it into an array like ["50810", "50811"] using .asJsonStringArray
Ultimately, I want to convert it into JSON object like [{ "mykey" : "50810"}, {"mykey" : "50811"}] so I can update a custom multi select field.
I tried to chain asJsonObject("mykey") but it is giving me JSON as [{ "mykey" : "["50810", "50811"]"}] instead.
I am guessing I need to create a new variable and iterate over mylist and format it the way I want but I am drawing blank.
Can someone please share if what I want is possible, if so, maybe share some example of how this could be achieved.
I think this could solve my other problem of updating labels I asked here --> https://community.atlassian.com/t5/Automation-questions/Advanced-Field-Editing-Add-Remove-labels-using-variable-smart/qaq-p/2551263
When iterating over a list, you may add additional text before or after the values...or even before / after the iterator itself.
Let's assume your list is stored as text in a variable named varMyList, with values of: 50810, 50811. And so the delimiter is ", " (a comma followed by a space).
That can be reformatted into text for use as your JSON with this:
[ {{#varMyList.split(", ")}}{ "mykey" : "{{.}}" }{{^last}}, {{/}}{{/}} ]
I recommend experimenting, writing the results to the audit log before trying an update operation, and adjusting until it works as expected. Then try the issue update to test things.
And please note: if you are trying this to support an advanced edit with JSON using the Issue Edit action, it appears the parsing does not fully evaluate smart values before trying to validate the JSON...potentially leading to errors when saving the action. The work-around for that is to first create the JSON expression in another variable, e.g., named varJson, and then using that in the edit action as {{varJson}}. This will force the smart value evaluation before the JSON validation.
Kind regards,
Bill
Thank you very much @Bill Sheboy I was able to "add" update a multi select field with list from variable.
As suggested, used your syntax --
[ {{#varMyList.split(", ")}}{ "add" : {"value" : "{{.}}" }}{{^last}}, {{/}}{{/}} ]
gave output: -
[ { "add" : {"value" : "2022-Q1" }}, { "add" : {"value" : "2022-Q3" }} ]
which i then stored in new variable (newVariable).
Then I was able to edit multi select field like below:
{
"update": {
"customfield_14400": {{newVariable}}
}
}
and it worked like charm. Thank you for showing and enlightening with this syntax!!
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.