Hi,
I have a custom field (customfield_11248) that I want to update with the contents of multiple multi-select custom fields. What I want to do is create this automation so that the following can happen:
customfield A: option 1, option 2, option 3
customfield B: option 4, option 5, option 6
automation would set customfield_11248 to be: option 1, option 2, option 3, option 4, option 5, option 6
If any values are added to or removed from customfields A and B, customfield_11248 would update appropriately. For example, if Option 2 was removed from customfield A, customfield_11248 would then appear with: option 1, option 3, option 4, option 5, option 6
I've tried multiple different JSON configurations but I can't get past being able to just adding to customfield_11248. updating or removing values always seems to be the hang up.
One additional caveat is that there are actually a total of eight different customfields that I want to feed into customfield_11248, so breaking it out by the different scenarios won't work here because I'd run out of steps in the automation. These fields can also be empty, so that needs to be considered as well.
Any help here would be appreciated. Thanks.
Hi @David Law -- Welcome to the Atlassian Community!
I recall from an earlier question an approach to solve this was to use the fieldChange smart values to build a dynamic JSON expression for the advanced edit, and perform all the adds and removes in one action.
If you have already tried that without success, please post an image of your complete automation rule, images of any relevant actions / conditions / branches, an image of the audit log details showing the rule execution, and explain what is not working as expected. Those will provide context for the community to offer ideas. Thanks!
Kind regards,
Bill
Hi @Bill Sheboy
Thanks for the response and the welcome.
I've actually spent hours reading through those links above and while they get me close to where I need to be, I think my lack of JSON experience is the main issue here.
For my rule, I'm pretty sure the layout of it is accurate. I used the "IF or ELSE" component and broke it out into two scenarios. One where if any of the eight custom fields have a value that exists and another where if all of the eight custom fields are empty. I then update customfield_11248 via JSON as follows (and I'm sure this is the problem because I keep getting an invalid JSON message in the audit trail):
Scenario 1:
{
"fields": {
"customfield_11248": [
{{#issue.customfield_11071}}{"value":"{{value}}"}{{^last}},{{/}}{{/}},
{{#issue.customfield_11070}}{"value":"{{value}}"}{{^last}},{{/}}{{/}},
{{#issue.customfield_11024}}{"value":"{{value}}"}{{^last}},{{/}}{{/}},
{{#issue.customfield_11027}}{"value":"{{value}}"}{{^last}},{{/}}{{/}},
{{#issue.customfield_11069}}{"value":"{{value}}"}{{^last}},{{/}}{{/}},
{{#issue.customfield_11029}}{"value":"{{value}}"}{{^last}},{{/}}{{/}},
{{#issue.customfield_11250}}{"value":"{{value}}"}{{^last}},{{/}}{{/}},
{{#issue.customfield_11251}}{"value":"{{value}}"}{{^last}},{{/}}{{/}}
]
}
}
Scenario 2: I don't have anything developed for this yet, as I figured the solution for the first scenario would just require tweaking to make the second work.
Is this enough info, or is there anything else I can provide?
EDIT: One point to add, the above works if all of the 8 have a value present. The issue where I get the invalid JSON message occurs when one or more of them is blank. So the above code needs to account for the scenario where any of them may be blank.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Without seeing your complete rule and audit log, I am guessing a bit here...
Looking at the expression you show, the expression for each field's iterator (e.g., for customfield_11071) is followed by a trailing comma.
{
"fields": {
"customfield_11248": [
{{#issue.customfield_11071}}{"value":"{{value}}"}{{^last}},{{/}}{{/}},
{{#issue.customfield_11070}}{"value":"{{value}}"}{{^last}},{{/}}{{/}},
{{#issue.customfield_11024}}{"value":"{{value}}"}{{^last}},{{/}}{{/}},
{{#issue.customfield_11027}}{"value":"{{value}}"}{{^last}},{{/}}{{/}},
{{#issue.customfield_11069}}{"value":"{{value}}"}{{^last}},{{/}}{{/}},
{{#issue.customfield_11029}}{"value":"{{value}}"}{{^last}},{{/}}{{/}},
{{#issue.customfield_11250}}{"value":"{{value}}"}{{^last}},{{/}}{{/}},
{{#issue.customfield_11251}}{"value":"{{value}}"}{{^last}},{{/}}{{/}}
]
}
}
As a result, the JSON could look like this if that first custom field 11071 was empty. That can be confirmed by looking at the audit log to see if that matches your observation for the empty fields.
{
"fields": {
"customfield_11248": [
,
{"value":"a"},
{"value":"b"},{"value":"c"},{"value":"d"},
{"value":"e"},
{"value":"f"},
{"value":"g"},
{"value":"h"},{"value":"i"},{"value":"j"},
{"value":"k"},
]
}
}
As you have already included the use of {{^last}},{{/}} for each iterator, perhaps try removing the trailing commas for each field's entry.
One challenge will still be if the last field is empty, as it has no trailing comma to finish well. And so one work-around is this is to pre-build the JSON and then clean it up:
{
"fields": {
"customfield_11248": [
{{varJsonForValues}}
]
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I've gone through what you provided and went the route of creating a variable. I've switched to a different set of fields now, so the custom field IDs are a bit different.
I have two multi select custom fields (IDs are 11019 and 11020). These are the source fields.
The target multi select custom field is ID 11316.
My Create Variable step (sets variable TechServicesVendors) is as follows:
{{#issue.customfield_11019}}{"value":"{{value}}"}{{^last}},{{/}}{{/}},{{#issue.customfield_11020}}{"value":"{{value}}"}{{^last}},{{/}}{{/}}
The Edit Issue step is as follows:
{
"fields": {
"customfield_11316": [
{{TechServicesVendors}}
]
}
}
The automation works perfectly assuming there's at least one value in both fields. If there's a blank, the audit log shows that the JSON is invalid.
I tried to remove the comma from the Create Variable step, but that only seems to be successful when one or both of the fields are blank. Otherwise, I get the invalid JSON message in the audit log.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
IMHO, these scenarios with empty values are quite the mess in rules: I have not found consistent practices to detect empty / no-value for the various types of selection fields.
I recommend creating variables for each selection fields' JSON, and then using conditions to decide when to concatenate them with commas.
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.