Script Runner: Clones an Issue and links_copy contents of custom field to description of new issue

Avril Bower
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.
January 11, 2016

Hello,

I currently have a Script Runner 'Clones an issues and links' post function set up during my 'start work' transition which opens a new task in another project.

Here is the current set up under the 'Addition issue actions' code block:

issue.summary = '[TW] ' + sourceIssue.key + ': ' + sourceIssue.summary
issue.description = 'Please document the following Change Request: ' + sourceIssue.summary + ' (' + sourceIssue.key + ').'
issue.priorityId = '4'
issue.assigneeId = 'Unassigned'

All of this works without issue. I have no import statements or anything else, the above is all of the code.

However, I have a request to add to the 'issue.description' line of the above. The addition will require me to copy the contents of a custom field in the existing task and paste it to the description field of the new task. 

I have written it like this:

issue.description = 'Please document the following Change Request: ' + sourceIssue.summary + ' (' + sourceIssue.key + ').\n \n ' + 'Dedicated information for Tech Writing from the change request: ' +  sourceIssue.13773

It works up until the '+ sourceIssue.13773', it will not pull in the additional text from the custom field.

Any ideas on what I can do to accomplish this?

Thank you in advance!

6 answers

1 accepted

0 votes
Answer accepted
Avril Bower
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.
January 12, 2016

I switched the 'Unassigned' with 'null' but it had no affect. I did find this in the logs:

2016-01-12 11:41:07,774 http-bio-443-exec-32 ERROR ab186104 701x562241x1 1goc7p6 153.65.184.112 /secure/CommentAssignIssue.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] *************************************************************************************

2016-01-12 11:41:07,775 http-bio-443-exec-32 ERROR ab186104 701x562241x1 1goc7p6 153.65.184.112 /secure/CommentAssignIssue.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: DMCP-2336, actionId: 131, file: null

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:

Script79.groovy: 1: unexpected char: 0xA0 @ line 1, column 80.

   (sourceIssue).find {it.name == 'Informat

                                 ^1 error

 

Still learning about all of this, I appreciate your patience. 

Thanos Batagiannis _Adaptavist_
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.
January 12, 2016

This is weird, could you rewrite the script instead of copy paste ?

Avril Bower
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.
January 27, 2016

That worked. Thank you. I will keep that in mind for future. 

1 vote
Thanos Batagiannis _Adaptavist_
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.
January 11, 2016

Avril,

The right way to get the value of the custom field is:

def cf = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Name of CF'}
def value = sourceIssue.getCustomFieldValue(cf)
issue.description = 'Please document the following Change Request: ' + sourceIssue.summary + ' (' + sourceIssue.key + ').\n \n ' + 'Dedicated information for Tech Writing from the change request: ' +  value

 Hope that helps

Kind regards

0 votes
Avril Bower
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.
January 12, 2016

Hey Thanos, 

Thank you for the information. I've added the def statements to the code, updated and published the workflow. Sadly, when I execute the transition on the task, the page will just refresh, it will not create the new issue at all. 

The code now looks like this:

 

def cf = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Information for Technical Writing'}
def value = sourceIssue.getCustomFieldValue(cf)
 
issue.summary = '[TW] ' + sourceIssue.key + ': ' + sourceIssue.summary
issue.description = 'Please document the following Change Request: ' + sourceIssue.summary + ' (' + sourceIssue.key + ').\n \n ' + 'Dedicated information for Tech Writing from the change request: ' +  value
issue.priorityId = '4'
issue.assigneeId = 'Unassigned'

Is there anything else I am missing?

Thank you for your assistance, 

Avril

Thanos Batagiannis _Adaptavist_
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.
January 12, 2016

Do you get any errors in you logs ?

Thanos Batagiannis _Adaptavist_
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.
January 12, 2016

Try to replace issue.assigneeId = 'Unassigned' with issue.assigneeId = null

0 votes
Thanos Batagiannis _Adaptavist_
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.
January 11, 2016

Avril in the script I posted below just replace with {it.name == 'Information for Technical Writing'} and you are done.

0 votes
Avril Bower
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.
January 11, 2016

Hey Thanos, 13733 is the field ID for my custom field which is named "Information for Technical Writing". I figured it would be easier to deal with the ID than the name. Thanks, Avril

0 votes
Thanos Batagiannis _Adaptavist_
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.
January 11, 2016

Hi Avril, What is the 13733 ? Is it a name for a custom field ?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events