Add custom field and its value in the newly created sub-task, using script runner

Used Builtin script listener to create sub-task and that part is working fine. Now trying to add a custom field, within automatically created sub-task. Name of the custom field to be CC_List and the value to be xyz@abc.com.

I followed Kostas' response at https://answers.atlassian.com/questions/196852/script-runner-create-subtask-built-in-script-postfunction
Used the following call, to get the custom field object

def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'CC_List'}

at this point, used "addCustomFieldValue" method and that did not work.
any suggestions please ? Not sure how to proceed

3 answers

tried the following (as available as an example)

 

def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'CC_List'}
issue.setCustomFieldValue(cf, 'docs@txe.com')
it still does not work.
Jamie - any clues please ? thanks
0 vote

If you just the right label, the right people will see this... that's generally more effective than sending me mail.

Using the built example worked for me:

def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'TextFieldB'}
issue.setCustomFieldValue(cf, 'my value')

but that's for a text field. What type of field is CC_List?

What versions are you using?

Jamie - thanks for looking into my request. We are using JIRA 6.1.7

CC_List is a custom field and type : UserPicker (multiple users).

Am I facing the problem, since it is not a text field ?  thanks

Yes, the type of the field is not irrelevant here. You need to set it to a collection of User objects, or ApplicationUser, can't remember which.

I am running into a similar problem where I can't set the value either. My field is a single select list type, and oddly enough I can have the field inherit the value from the parent, but I can't seem to set it to a different value.

How/where would you specify the type of field? When I use the code below, the sub-task fails to create, however if I follow the template for copying the value from the parent, the sub-task creates and inherits the value properly.

def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'CustomFieldName'}
issue.setCustomFieldValue(cf, 'my value')

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Monday in Jira Software

How large do you think Jira Software can grow?

Hi Atlassian Community! My name is Shana, and I’m on the Jira Software team. One of the many reasons this Community exists is to connect you to others on similar product journeys or with comparabl...

596 views 6 12
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you