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.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online 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.