Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Inherit multi-select field from hierarchy parent using automation

Julia Foden
Contributor
November 4, 2021

Hi

In a hierarchy which has Milestone and Feature levels above Epic, I need to make Features inherit a multi-select field from their parent Milestone when they are created.

In testing I have created a rule that works for a single select field, as described in my answer to this question. But how to make it work for a multi-select field? The variable contains a comma-separated list. How can I manipulate that so that each value is added to the field on the created Feature?

Can I split the comma separated list into a new smart value that can be branched on?

Any other suggestions welcome, if there is a better way of going about this.

Thanks

1 answer

1 accepted

0 votes
Answer accepted
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 4, 2021

Hi @Julia Foden 

Without seeing your rule, I suggest the answer is "maybe".  Please take a look at advanced branching for options to iterate over the values from a list.  (You may use list functions and the CSV values you note to drive the branching.)

https://community.atlassian.com/t5/Automation-articles/Branching-over-smart-values-in-Jira-Automation/ba-p/1741935

Kind regards,
Bill

Julia Foden
Contributor
November 4, 2021

Hi @Bill Sheboy 

This is what I have 

Screenshot 2021-11-04 175446.png

Strategic Initiative is a multi select field and the log output is a comma separated list. If there is just one value it edits the field on the trigger issue correctly.

I tried branching over the variable {{SI}}

Screenshot 2021-11-04 175938.png

and then using this to update the field

Screenshot 2021-11-04 180000.png

but the error was 

(Option value 'ABC, XYZ' is not valid (customfield_16576))

 

Is it possible to manipulate my variable {{SI}} (comma separated list) in such a way that Advanced Branching recognises it as a list that can be branched over?

Thanks for your help.

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 4, 2021

Yes, now that you have confirmed that {{SI}} contains a comma-separated values (CSV) list of the data you want, change the Advanced Branch to use:

{{SI.split(",")}}

That will convert it into a list which is then input to the branch.

Julia Foden
Contributor
November 5, 2021

Ah thanks @Bill Sheboy , that's the final hurdle!

What a palaver though, to copy one field from the parent. Do you happen to know if there is a feature request in to enable copying a field from the hierarchy parent, in the same way that we can from the Epic, trigger issue etc?

Julia Foden
Contributor
November 5, 2021

Actually no @Bill Sheboy I spoke too soon. It works fine if there are 1 or 2 values in the list. But if there are more it only copies 2 values to the child.

I tried with 3 values and 4 values and in my advanced branch I logged the value before going into the edit action. Both times it logged each value correctly, but only 2 values were added to the child. And not necessarily the first two in the list!

I guess this is because all the branches were simultaneously trying to edit the same field?

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 5, 2021

Argh, branches!   :^)

Okay, branches which process more than one issue are executed asynchronously, and there is no guarantee of when they will finish...so, your writes may be walking over each other as the loop progresses.

Let's try this: in the branch, after you make the edit to add the value, insert a Re-fetch action.  This will reload the issue before proceeding, dramatically slowing down the rule, and improve the chances of all of the values sticking.

Julia Foden
Contributor
November 5, 2021

Aaarghhh indeed!

I tried with the re-fetch but it still only added 2 values :( 

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 5, 2021

Hmm... Would you please post an image of your current, complete rule, and of the audit log from an execution where it only adds some of the values?

Julia Foden
Contributor
November 5, 2021

Here you go @Bill Sheboy 

Screenshot 2021-11-05 170444.png

 

Screenshot 2021-11-05 170559.png

In this case it added the 1st and 4th values.

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 5, 2021

Puzzling that still doesn't work; still gotta be the branching. 

I can think of one other way to try this: Get rid of the branch on the created variable, and try to update directly by forming the JSON using list functions.

First, create a new variable, named SIJson, with the value from your first branch, instead of {{SI}}

{{#issue.Strategic Initiative}} "add": { "value":"{{value}}" }, {{/}}

Then try to use that variable in a JSON edit of your trigger issue's field (without the second branch)

{ "update": {
"customfield_16576": [ {
{{SIJson}}
} ]
}
}

Sorry, if that does not work, I am stumped, and it may be time to submit a support ticket to see if they can help: https://support.atlassian.com/contact/#/  Your site admin can do that if you are on a paid Jira license.

Julia Foden
Contributor
November 8, 2021

I finally got it working @Bill Sheboy , thank you for your suggestion.

The variable as you suggested is

{{#issue.Strategic Initiative}} { "value":"{{value}}" }, {{/}}

And then the edit is

{ "fields": {
"customfield_16576":
[{{SIJson.substringBeforeLast(",")}}]

}

 Thank you very much for your help. 

Like Bill Sheboy likes this
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 8, 2021

Awesome!  I am glad to learn you got it solved.

FYI for that list to build the string: you can also use conditional logic to not add the last comma, and so eliminate the need for the call to substringBeforeLast()

{{#issue.Strategic Initiative}} { "value":"{{value}}" }{{^last}}, {{/}}{{/}}
Like Julia Foden likes this
Julia Foden
Contributor
November 9, 2021

Thanks Bill. Can you please point me to any good documentation on this, and other possibilities. I've not seen {{^last}} before.

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 10, 2021

I wish there was better/more organized documentation on smart values.  Until that improves, it helps to read over all of the examples to learn what is possible.

For example, here is the stuff on lists where you can see things like {{^last}} 

https://support.atlassian.com/jira-software-cloud/docs/smart-values-lists/

And also this list of sources from the automation product team:

https://community.atlassian.com/t5/Automation-articles/Jira-Automation-all-the-resources-you-need-in-one-page/ba-p/1388465

Like Julia Foden likes this

Suggest an answer

Log in or Sign up to answer