/** This example script listner script must bve configured to fire on the 'Worklog Created' Event and shows how when work is logged that you can transition an issue to 'In Progress' and then to 'Done' when the remaining estimate reaches 0. * "All right, title and interest in this code snippet shall remain the exclusive intellectual property of Adaptavist Group Ltd and its affiliates. Customers with a valid ScriptRunner* license shall be granted a non-exclusive, non-transferable, freely revocable right to use this code snippet only within their own instance of Atlassian products. This licensing notice cannot be removed or* amended and must be included in any circumstances where the code snippet is shared by You or a third party." */// log out the worklog that was added to the issue incase it is needed for debugging purposeslogger.info("the worklog is: "+worklog)// Get the issue object that the worklog was added on.defissue=get('/rest/api/2/issue/'+worklog.issueId).header('Content-Type','application/json').asObject(Map).bodylogger.info("Issue object is : "+issue.fields)// get the remaining estimate value of the issue.defremainingEstimateValue=issue.fields.timetracking.remainingEstimateSecondslogger.info("Remaining Estimate Value Is:"+remainingEstimateValue)// If the remaining estimate value is not 0 then transition the issue to the In Progress statusif(remainingEstimateValue!=0){logger.info("Issu has no time left remaining so transition to Done")// specify the ID for the In Progress transition of the workflow belowdefinProgressTransitonID='<InProgressTransitionIDHere>'// The rest call to transition the issuedefinProgressTransition=post("/rest/api/2/issue/${issue.key}/transitions").header("Content-Type","application/json").body([transition:[id:inProgressTransitonID]]).asObject(Map)// Check if the issue was transitioned correctly// Log out the issues updated or which failed to updateif(inProgressTransition.status==204){logger.info("The ${issue.key} issue was transitioned by the listiner.")}else{logger.warn("The listiner failed to transition the issue. ${inProgressTransition.status}: ${inProgressTransition.body}")}}// If the remaining estimate value is 0 then transition the issue to the closed statusif(remainingEstimateValue==0){logger.info("Issue still has time on the estimate so transition to In Progress")// specify the ID for the Done transition of the workflow belowdefdoneTransitonID='<DoneTransitionIDHere>'// The rest call to transition the issuedefdoneTransition=post("/rest/api/2/issue/${issue.key}/transitions").header("Content-Type","application/json").body([transition:[id:doneTransitonID]]).asObject(Map)// Check if the issue was transitioned correctly// Log out the issues updated or which failed to updateif(doneTransition.status==204){logger.info("The ${issue.key} issue was transitioned by the listiner.")}else{logger.warn("The listiner failed to transition the issue. ${doneTransition.status}: ${doneTransition.body}")}}
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.