I have an incident level: P1, P2 or P3 which user must input in the workflow after open status. I would like to set:
if P1, due date = now + 2 hours
if P2, due date = now + 1 day
if P3, due date = now + 2 days.
Is there a way to do this in workflow post functions? Thanks
Hi @Alan Sim
You can do it by creating project automation rule (check below). i just want to remind you that due date is a date field not Date time, so you won't have the precision of time in hours. The workaround here is to create a new custom field of type DateTime to use it instead.
ProTip: you can switch between function now.PlusDays and nowPlusBusinessDays according to your support level 24/7 or normal business days.
Let me know if you have any questions
Thanks a ton Karim. The project automation works.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Alan! I am not sure if that is possible using post functions, at least not what I can recall or find after a quick check.
What you can do, is use project automation for that.
You can have the trigger to be when a new issue is created, or when it transitions (I am not sure from your question what fits better).
Then you can have a check if P1, P2 or P3 is selected, and accordingly you can set the due date.
Would this be an option for you?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Alan,
Use this code to add the hours to the current date
def hoursToIncrement = 2
def date = new Date()
def calendar = Calendar.getInstance()
calendar.time = date
calendar.add(Calendar.HOUR_OF_DAY, hoursToIncrement)
def incrementedDate = calendar.time
Use this code to add the days to the current date
def daysToIncrement = 1
def date = new Date()
def calendar = Calendar.getInstance()
calendar.time = date
calendar.add(Calendar.DAY_OF_YEAR, daysToIncrement)
def incrementedDate = calendar.time
and use the rest API in the post function to update the due date with the above's values.
// Specify the issue key to update
def issueKey = '<IssueKeyHere>'
// Get today's date to set as the due date
def today = new Date()
// Update the issue
def result = put("/rest/api/2/issue/${issueKey}")
.header('Content-Type', 'application/json')
.body([
fields:[
// Set the due date to today's date
duedate: today.format('yyyy-MM-dd') as String
]
])
.asString()
// Validate the issue updated correctly
if (result.status == 204) {
return "Success - The issue with the key of ${issueKey} has been updated with a new due date"
} else {
return "${result.status}: ${result.body}"
}
Thanks,
Sachin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sachin, just a question, you are setting today's date as the expiry date. And you are not informing what language you are using (Groovy).
Your code does not seem to do what he asks for.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Its Groovy he can use in the post function ( As he asked for) on Open status.
In the Code We are taking current date and increment it by hours/days and then we can set that date to due date custom field.
Its just Not a complete code he need to use as per his requirement.
Provided he will need a Script Runner Plugin.
Thanks,
Sachin
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.