Script Runner: Clones an issue, and links

David Willox August 16, 2017

How can I use the below script to set the value of an issue field such as "Description" instead of a custom field?

def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'field name'}
issue.setCustomFieldValue(cf, 'Non-project')

Also how can I use the above script or a mod of it to set a date picker custom field to 3 days from the current date?

 

Thanks for your help guys.

 

David

1 answer

0 votes
Joshua Yamdogo @ 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.
August 17, 2017

I think this page in our documentation is exactly what you are looking for: https://scriptrunner.adaptavist.com/latest/jira/recipes/workflow/postfunctions/set-issue-attributes.html

Essentially, you can set non-custom fields like this in post-functions:

// system fields
issue.setDescription(
"A generated description")
issue.setDueDate(
new Timestamp((new Date() + 1).time)) // set due date to tomorrow
David Willox August 17, 2017

Hi Joshua,

 

Thanks for the help.

Using your input I built the below script. The script is parsed and no errors are shown but it is not creating a linked item. Please let me know where I am going wrong here!

def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Project Name'}
issue.setCustomFieldValue(cf, 'Non-project')
issue.setDescription('Review the listed exception(s) for approval.')
def usercf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Deloitte/Technical Lead'}
issue.setCustomFieldValue(cf, 'VDLT DL QualityTeam')
def textcf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Estimate'}
issue.setCustomFieldValue(cf, '1')
def dateCf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Desired Completion Date'}
issue.setCustomFieldValue(dateCf,((new Date() + 1)))

 

Thanks,

 

David

Joshua Yamdogo @ 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.
August 21, 2017

Hi David,

There are two things I'd look at.

First, did you place that code in the "Additional issue actions box"? It should go in the Additional issue actions box, not the Condition box.

Screen Shot 2017-08-21 at 2.20.52 PM.pngSecondly, did you put the post function in the correct order? Your post function should be the very last thing, like this:

Screen Shot 2017-08-21 at 2.22.46 PM.pngFinally, remember to publish your workflow.

David Willox August 31, 2017

Hi Joshua,

Still no luck sorry. Here is my setup:

 

Create_Action.jpg

Joshua Yamdogo @ 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.
August 31, 2017

Hi David, 

Your setup looks correct. I think you are very close to getting this to work. One problem I noticed is that your script doesn't define the customFieldManager.

Add this to the top of the script:

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()

Another thing is that the usercf field may not be able to be set like that. What type of field is usercf? Is it a user picker field, group picker, etc? You might try commenting out or removing the lines where you get usercf and set usercf and then try to run the script again after adding the above code.

Suggest an answer

Log in or Sign up to answer