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

Sam Rajagopal June 29, 2015

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

0 votes
Sam Rajagopal July 1, 2015

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

JamieA
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.
July 2, 2015

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.

Nicholas Kim December 20, 2016

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')
0 votes
JamieA
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.
July 1, 2015

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?

0 votes
Sam Rajagopal June 30, 2015

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

Suggest an answer

Log in or Sign up to answer