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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
Secondly, did you put the post function in the correct order? Your post function should be the very last thing, like this:
Finally, remember to publish your workflow.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.
Register NowOnline forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.