Need help setting an absolute dueDate in Scriptrunner on a transition

Brendan Clough January 11, 2017

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

2 votes
Answer accepted
Jon Bevan [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.
January 11, 2017

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

Brendan Clough January 12, 2017

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?

Jon Bevan [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.
January 16, 2017

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