Script Runner: Clones an issue, and links

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 Community Champion Aug 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

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 Community Champion Aug 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.

Hi Joshua,

Still no luck sorry. Here is my setup:

 

Create_Action.jpg

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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,042 views 13 18
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot