Hi dear Community,
I'm stumped that I can't get the solution of How-to-combine-values-from-various-multiple-select-fields to work in my usecase.
The setup:
The problem is quite similar to the question linked above. I have a top-level Movement issuetype that has children of the Initiative issuetype. On both the Movement and Initiative issuetypes I have the same custom field (customfield_10301, which I'll call "Domain" in the rest of this post) that is a multiselect list with five possible entries (call them A, B, C, D and E).
My Goal:
If the Domain entry of one of the Initiatives changes, I need to reflect that change in the value of the Domain entry that resides on the parent Movement Jira item.
Example:
Initiatives 1 and 2 are children of Movement X , and their customfield is filled like this:
Initiative 1 Domain: A, B, D, E
Initiative 2 Domain: A, C
Movement: Domain: A, B, C, D, E
If the Domain value of initiatieve 1 changes to A, B, D, Movement X to be filled with: A, B, C, D (which is a logical "or" executed on the values of the Domains of its children).
Step by Step:
0: The trigger of the automation would be a change in the Domain value of an Initiative
Followed immediately by the check if it's an Initiative that we're dealing with:
And checking if the Initiative indeed has a parent Movement
1: As per @Bill Sheboy's solution in the link above, I first lookup the issues:
And I verify the lookup by logging it (the correct issues are looked up) using
This indeed gives me the initiatives that are children of the parent Movement of the trigger Initiative (the square brackets are there to more easily see an empty result).
2: I then branch into the parent Movement by
and then apply the magic in Bill's solution by editing the Movement using the more options and then Json with the smart values on the looked-up Jira items:
{
"update": {
"customfield_10301": [
{{#lookupIssues.customField_10301.value.flatten.distinct}}
{
"add": { "value": "{{.}}" }
} {{^last}},{{/}}
{{/}}
]
}
}
3: As you might've guessed (if you've read so far), the magic didn't happen in my case.
I've been dabbling with creating variables inside the automation and writing their content to the audit log, to find out what is going on. It seems that as soon I'm using either flatten or distinct, I end up with an empty Domain value.
What am I missing here?
Kind regards,
Dick
Hello @Dick,
Your diagnosis looks right to me: on Data Center, the Lookup Issues action only exposes a limited set of stock fields, so {{lookupIssues.customfield_10301}} comes back empty no matter what you chain after it. That matches the open suggestion you linked, and it explains why the same rule works for @Lalithesh on Cloud.
Since you're heading down the web request route, the shape that should work on DC:
/rest/api/2/search?jql='parent link' = {{triggerIssue.parent link}}&fields=customfield_10301, with "Delay execution" enabled so the response is available to later steps.fields.customfield_10301[].value)./rest/api/2/issue/{{triggerIssue.parent link}} with the update JSON in the body.Use a dedicated service account token for the auth header rather than a personal one, and log {{webResponse.status}} to the audit log while testing. The exact smart value names vary a little between DC versions, so verify them with an audit log entry first.
Best,
Ivan
Following up on my earlier answer, @Dick: depending on why the Movement needs the combined value, there may be a way to skip the write-back entirely. If you're open to using an app from the Atlassian Marketplace, JXL for Jira can help with this. Specifically, its formula columns allow you to compute the union of the children's Domain values live on each Movement row:
const values = this.hierarchy.children
.flatMap(c => c.domain ?? [])
.map(o => o.value);
return [...new Set(values)].join(", ");
It runs on Data Center, and the Movement > Initiative relationship works through the same Parent Link your hierarchy already uses. The computed value updates as Initiatives change and comes along in exports. The caveat: it's a display column, so if other JQL or boards must read the real Domain field on the Movement, your REST route is still the right call.
Disclosure: I work for the team that builds JXL.
All the best,
Ivan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ivan Manolov _Appfire_,
A couple of things I would like to mention:
So the story to nailing this continues.
Kind regards,
Dick
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Tiny result
Using:
<our instance>/REST/API/3/search?jql=%27parent%20link%27%20%3D%20{{MovementKey}}
gives me a Response 200 and a
Request GET with the complete path
The {{webhookResponse.body}} however contains a lot of stuff that isn't related to specific Jira Items. Even this came along:
{{webhookResponse.body}}
{\u0022product\u0022:\u0022jira\u0022,\u0022destination\u0022:\u0022/REST/API/3/search?jql\u005Cu003d%27parent%20link%27%20%3D%20DIR-1\u0022,\u0022forgotLoginDetailsUrl\u0022:\u0022/secure/ForgotLoginDetails.jspa\u0022,\u0022signupUrl\u0022:\u0022/secure/Signup!default.jspa\u0022,\u0022permissionsViolationContext\u0022:{\u0022showLoginForm\u0022:true,\u0022warningMessages\u0022:[\u0022\u005Cu0027starm001\u005Cu0027 does not have permission to access this page.\u0022,\u0022If you think you shouldn\u005Cu0027t get this message, please contact your Jira administrators.
DIR-1 is indeed the MovementKey. But I'm admin of this Jira instance, and all the projects that are in scope of the Automation that runs the Webrequest. I'm a bit baffled by the permissions violation.
Here's hoping :)
Dick
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Dick,
I'll pass the greetings along :)
Your 200-with-login-page result can be caused by two things, fixable in the web request config:
Wrong API version for Data Center. /rest/api/3/ only exists on Cloud. On DC use lowercase /rest/api/2/search?... (or /rest/api/latest/). Your uppercase /REST/API/3/ path doesn't hit the REST servlet at all, which is why Jira answered with a regular web page instead of JSON.
The request is anonymous. A web request doesn't inherit the automation actor's session, so Jira treated the call as not-logged-in ('starm001' and the login form in the body are the giveaways). Add two headers to the action: Authorization: Bearer <token> using a Personal Access Token (create one under the service account's profile, Personal Access Tokens, available since Jira 8.14), and Accept: application/json.
Before wiring this back into the rule, I'd prove the calls outside automation with curl (or Postman: Authorization tab, type Bearer Token). That separates Jira-side URL/auth problems from smart value problems:
curl -s -H "Authorization: Bearer <PAT>" -H "Accept: application/json" \
"https://<your-instance>/rest/api/2/search?jql=%27parent%20link%27%20%3D%20DIR-1&fields=customfield_10301"
If that returns the children with their Domain values, the same URL and headers dropped into the Send web request action will too. The PUT can be tested the same way (against a test Movement first, since it overwrites the Domain field):
curl -s -X PUT -H "Authorization: Bearer <PAT>" -H "Content-Type: application/json" \
-d '{"fields":{"customfield_10301":[{"value":"A"},{"value":"B"}]}}' \
"https://<your-instance>/rest/api/2/issue/DIR-1"
Once both work standalone, in the rule log {{webhookResponse.body.issues.key}} to confirm the response parses, then try building the union with {{webhookResponse.body.issues.fields.customfield_10301.value.flatten.distinct}} before the PUT step.
On the urlEncode parse error: your manual percent-encoding is a perfectly fine permanent fix, no need to fight the smart value there.
Cheers,
Ivan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ivan,
It was your point 1: The call to the api had flaws.
/rest/api/2/search?jql=%27parent%20link%27%20%3D%20{{MovementKey}}
gives me the initiatives now properly using the log action with this message:
Looked up issues = [ {{webhookResponse.body.issues.key}} ]
I already added the Authorization and Bearer <PersonalAccessToken> combination in the managed secret keys section of Jira, which meant I could rule-out your second suggestion.
Thank you kindly for your support in this matter.
Dick
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
A silver lining, but in the end falling flat on my face:
Why isn't flatten working for me?
OpenJDK-21 perhaps?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ow bummer: Lookup issue action - Add support for more fields on JIRAAUTOSERVER-877
this should've been tackled for Jira Datacenter 3 years ago...
My list is empty to begin with!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Going for the How to sum story custom filed values to an epic? solution using web request to the REST API mentioned in the comments by Bill.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi there, @Lalithesh.
It seems that you use Jira Cloud. I'm using Datacenter version 10.3.24 (indicated in the tags on the right). I'm sorry, but I'm not particularly looking for a confirmation that the solution works in Jira Cloud.
Hi there, @Gor Greyan
I noticed the extra parenthesis after flatten(), which were neither present in the referred, nor my solution. That would be a good catch, I'll try it and report back.
Thank you both for your efforts regarding this.
Kind regards,
Dick
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
These pictures contain the test Gor asked. The parentheses after flatten are not making a difference.
I'm now suspecting our underlying Java (openJDK-21).
Kind regards,
Dick
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah okay. Apologies, I missed the tags
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Dick
Thanks for the reply.
The interesting part of your audit log is that the lookup itself works correctly, while the Domain expression is already empty before distinct really becomes relevant.
I would therefore go one level simpler and inspect how Automation for DC is exposing this particular multi-select field.
Could you try logging these directly, without flatten or distinct? {{triggerIssue.customfield_10301}}
{{triggerIssue.customfield_10301.value}}
and, after the Lookup
{{lookupIssues.customfield_10301}}
{{lookupIssues.customfield_10301.value}}
I'd use the field ID rather than Domain for this test, just to remove field-name resolution from the equation.
Regards,
Gor
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Dick
I was able to reproduce the automation using the details shared here, and it worked without any issues.
Automation screen grab for reference
Cheers!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
wee change to the Edit action: the update function will only add value but it will never remove values that are removed from the child tasks.
Use this JSON instead
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Dick
I think the issue is with the structure returned by the multi-select field, not the lookup itself.
lookupissues gives you a list of work items, and each work item has its own list of Domain options. So effectively you have a list of lists. You need to flatten that collection first and then apply distinct.
I would first test this directly in the audit log:
{{lookupIssues.customfield_10301.value.flatten().distinct}}
With your example:
Initiative 1 --- A, B, D
Initiative 2 --- A, C
This should return
A, B, D, C
I found that funcitions here.
https://support.atlassian.com/cloud-automation/docs/jira-smart-values-lists
One thing I would change in your JSON is that you're using the option values to build the update manually. For a multi-select field, I would first confirm exactly what Automation is returning before constructing the JSON.
Please set these 3 logs; they will tell us at what level the value becomes empty.
{{lookupIssues.customfield_10301}}
{{lookupIssues.customfield_10301.value}}{{lookupIssues.customfield_10301.value.flatten().distinct}}
Regards,
Gor
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.