JMWE - Create/Clone Post Function - Iterator for custom field

Jonathan Chatwin June 4, 2019

Hey there,

on a transition screen I'm asking for WR #'s. I want each of these WR #'s, entered in a custom field ('Clone to WR's') separated by a comma to be a new issue created/cloned and set a custom field to that value in each.

The custom field to set is WR# on the new issues. The transition screen is asking for a comma separated list of WR #'s. It is to clone this current issue to the number of WR #'s in this custom field separated by a comma. ie: WR1234, WR1235, WR12356 - Would be three new cloned issues. 

How would I do this in Groovy Iterator, I can't really find any good examples to work from...?

 

Second option would be to just ask for a number of issues to clone from a drop-down on the transition screen and then just clone that many. If the first example in nonsense, then the second example would be good enough.

 

Any help would be appreciated. Thanks so much. 

1 answer

1 accepted

1 vote
Answer accepted
Radhika Vijji _Innovalog_
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.
June 4, 2019

Hi Jonathan,

First option:

Since the user passes a string with comma-separated values, then you need to first create an array with the value provided and use it in the iterator, like this:

def newArr =[]
issue.get("<custom field name>").split(",").each{
newArr += it
}
newArr

And to set the newly created issues with the same value, you can use the "it" variable that holds the value from the iterator script. Select the WR field under "Set fields of new issue" and write the following code:

it

Caveat: Since it is a user input if a WR has a comma in it, then the post-function might create an extra issue.

However, if the custom field ('Clone to WR's') is a multi-valued select field (if you could change it, like an issue selector), it would be more reliable. You need to then provide the following script under the Iterator field in the post-function.

issue.get("<custom field name>")

And to set the newly created issues with the same value, you can use the "it" variable that holds the value from the iterator script. Select the WR field under "Set fields of new issue" and write the following code:

it.value

 Hope this helps,

Radhika

Jonathan Chatwin June 5, 2019

Thanks so much. Works great. 

Suresh July 23, 2024

@Radhika Vijji _Innovalog_ 

In the same Create / Clone Issue(s) Post Function by JMWE

, I am creating 2 Tasks with 2 different summaries and custom field populated with 2 different drop-down values

[
[summary:"Brand | Fiscal Year, Quarter | Promotion Name | PL TSR (no ticket codes) Review (Comment Section)*",customField_20001:"Gotham"],
[summary:"Brand | Fiscal Year, Quarter | Promotion Name | TA Builder Analyzes PLUs & Review Master Data*",customField_20001:"Olympus"]

]

While Tasks are getting created with summary value, custom-field value (ID 20001) is not being set. Any idea where I am going wrong?

Suggest an answer

Log in or Sign up to answer