Need help setting an absolute dueDate in Scriptrunner on a transition

I need help with setting up a transition post function to change the due Date of an Issue. I've added on Script runner as I get the impression that this is the only path possible to achieving what I want to.

Now not having any experience in Java/ Groovy, to say I am a noob would be putting it kindly, but I have had a first attempt at it anyway. Would this work?

def newDueDate = "31/03/2017"
 
put("/rest/api/2/issue/${issue.key}")
	.header("Content-Type","application/json")
	.body([
		fields:[
			due: newDueDate
		]
	])
	.asString()
 
logger.info("dueDate of " & newDueDate & "set successfully")

Note :: I just want to confirm that this is the correct approach as we only have a single instance of JIRA cloud, therefore any code I load will be going into the production environment and I would rather not mess this up.

1 answer

1 accepted

Hi @Brendan Clough,

There are only three small changes you need to make to that script.

First, the date should be in YYYY-mm-dd format.
Second, to join strings/text together you need to use the + symbol, not the &.
Third, the field is referenced as duedate, not due. 

def newDueDate = "2017-03-31"
 
def response = put("/rest/api/2/issue/${issue.key}")
    .header("Content-Type","application/json")
    .body([
        fields:[
            duedate: newDueDate
        ]
    ])
    .asString()
// If the request fails, this will print out a nice message in the logs
// showing you what the error response was.
// The 204 number here is the HTTP Status code for No Content, which is
// the documented response from this REST API
assert resp.status == 204
logger.info("dueDate of " + newDueDate + "set successfully")

Feel free to ask if you have any more questions, or raise a support ticket - there is a link to our support portal from the Diagnostics & Settings page provided by the addon.

Thanks,
Jon

Awesome thanks mate! When an issue transitions, is it possible to determine what status it was in before the transition? Or what transition it is moving to?

Yes! You get a variable, transitionInput, in the script's context which contains this data: https://developer.atlassian.com/static/connect/docs/latest/modules/jira/workflow-post-function.html#triggered

When adding a Post Function, if you click on the ? button underneath the Code editor you'll get a popup dialog with a list of the variables that are already available in your script.

Suggest an answer

Log in or Join to answer
Community showcase
Teodora [Botron]
Published Thursday in Marketplace Apps

Jira Inferno: The Nine Circles of Jira Administration Hell

If you spend enough time as a Jira admin - whether you are managing a single, mid-sized instance, a large enterprise one or juggling multiple instances at once - you will eventually find yourself in ...

239 views 0 11
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
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