When trying to connect a custom multiselect dropdown field to the Fix version field via automation, I receive an error:
The Fix versions and the multiselect dropdown fields have the same values and are apart of the same project which is odd. I was able to automate these fields together when using a single field but needed to change the automation code to account for multi selections.
Here is a screenshot of my automation set up:
Any idea what the issue might be here? Thanks for any help in advance! šš¼
So, a couple of things.
1. If somebody selects multiple versions, this will probably break, because you'd potentially be trying to set the field to:
[{"name":"5.1","5.2","5.3"}]
2. I don't think you need the full {{/changelog.customfield_10050}}. {{/}} should do.
But anywho, I think what you need to do is:
{
"fields": {
"fixVersions" : [ {{#changelog.customfield_10050}} { "name": "{{fromString}}" }{{^last}} , {{/}} ]
}
}
This code is untested. For debugging purposes, I always recommend adding an action to write to the Audit log. I would throw the whole "fixVersions..." line in there.
Thanks for the response, Darryl! Ya, I've been noticing some odd behavior when doing multiple field selections.
When entering your code above, then attempting to publish changes, I got the following error:
Error while parsing additional fields - Failed to close 'changelog.customfield_10050' tag
I think it has something to do with:
{{^last}} , {{/}}
When I removed the {{^last}} , it seemed to get rid of the error but still no dice with the automation.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
AUGH, I forgot an extra {{/}} closing tag that was messing me up for while, then I remembered this discussion:
Which led to this bug:
https://codebarrel.atlassian.net/browse/AUT-2013
And this one:
https://jira.atlassian.com/browse/JRACLOUD-74953
In summary: {{changelog}} is kinda borked for multi-select fields. HOWEVER, I think {{fieldchange}} will work. I was at least able to get the values out. Let me see if I can tweak it to actually generate usable JSON...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Eh, I got close, but no cigar.
{{fieldchange.toString}}
Will return: 5.1,4.0
But as previously mentioned, your data needs to be in this format:
[{ "name": "5.1" },{ "name": "4.0" }]
So I tried what sounded like a perfect function:
{{fieldchange.toString.asJsonObjectArray("name")}}
But that gave me nothing. I thought it might be because toString was returning a string. Ok fine, s
o I tried:
{{fieldchange.to}}
That returned a more promising:
[10081, 10082]
But when I tried to feed it to asJsonObjectArray, still nothing. (Oh, and to @Nic Brough -Adaptavist-'s point, those are option values, not actual names of options, so even if I ended up with a proper JSON Object Array, the values would be all wrong.)
I'm getting the sneaking suspicion that fieldchange is not like other fields. :-{
To complete my futile journey, I tried one more horribly hacky thing:
{
"fields": {
"fixVersions": [ "name" : "{{fieldchange.toString.replaceAll("," , " \" \"name\" : \" ")}}"
}
}
The thought here is that I could use a text function to insert the necessary JSON tags and formatting. But... nope.
So, in summary.... I think I need to file a bug.
Also, how did I get this weird font? Huh.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Wait. I'm an idiot. We don't need to bother with fieldChange or changelog at all.
Because your field will already have been changed when the Automation is triggered, you should be able to use:
{{issue.customfield_10050}}
Maybe that will work with one of the aforementioned functions. Let me give that a whirl.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Bam. That did it. Try this:
{
"fields": {
"fixVersions" : [ {{#issue.customfield_10050}} { "name": "{{value}}" }{{^last}} , {{/}}{{/}} ]
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Darryl! This is awesome. It works for me now. Thank you so much for the help and effort you put into this šš¼
Gonna keep testing on my end but all seems to be good to go :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am finalizing this automation flow and am running into a final issue which I posted here for anyone that might have a similar use case.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think this is the problem:
"The Fix versions and the multiselect dropdown fields have the same values"
They do not. They might have the same text in their names, but the fields contain different values. A version field contains a version object, and a multiselect list contains one or more option objects.
To compare them, you'll need to code for looking at their names, not just the values.
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.