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

This widget could not be displayed.

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
This widget could not be displayed.

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?

This widget could not be displayed.

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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

111 views 2 0
Join discussion

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