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

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

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. 

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

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

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

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

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

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

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

Do you get any errors in you logs ?

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

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 May 30, 2018 in Marketplace Apps

Three tips for boosting your board's efficiency with Story Maps

Trello is one of the most effective tools for driving your sprints. It's customizable for every Agile team and product owners and Scrum masters (SM) love it. However, Agile teams often struggle with:...

849 views 2 9
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