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

This widget could not be displayed.

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

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 Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

88 views 1 0
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