Hi everyone,
I'm a newbie with groovy script and ScriptRunner.
I search a script in Post fonction to set the due date regarding the priority field value.
I have found some examples but they doesn't work.
The first example I've found is :
def dueDateField = issue.dueDate def Sev = issue.priority def dateToSet if (Sev == "Critical") { dateToSet = new Date() + 1 } else if (Sev == "Hight") { dateToSet = new Date() + 5 } else if (Sev == "Medium") { dateToSet = new Date() + 20 } else if (Sev == "Low") { dateToSet = new Date() + 30 } else if (Sev == "Lowest") { dateToSet = new Date() + 90 } issue.setDueDate(dateToSet)
I have put it into the Custom ScriptRunner Post Fonction of creation transition.
I can save it without error and no failure when the script is running but the field Due date stay empty.
Do you have any idea ?
Thanks for your answer.
I work on Jira Software 8.3.4 with ScriptRunner 5.9.1-p5.
I have made some pseudo Groovy code. But important thing to look at is the last line in the code example where the actual issue update is happening.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
MutableIssue mutableIssue = issueManager.getIssueObject(issue?.id);
def priorityField = mutableIssue.priority
def dateToSet = null
if (priorityField == "Critical") {
dateToSet = new Date() + 1
} else if (priorityField == "Hight") {
dateToSet = new Date() + 5
} else if (priorityField == "Medium") {
dateToSet = new Date() + 20
} else if (priorityField == "Low") {
dateToSet = new Date() + 30
} else if (priorityField == "Lowest") {
dateToSet = new Date() + 90
}
// Set date
mutableIssue.setDueDate(dateToSet)
// Update issue
issueManager.updateIssue(user, mutableIssue, EventDispatchOption.ISSUE_UPDATED, false)
Hope this will help you get further.
Regards
Lasse Langhorn
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
While looking for examples I came across several codes that allowed me to create the following code, which allows to shift the due date calculated if it falls on a weekend but nothing on the addition of working days and not calendar.
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.event.type.EventDispatchOption import com.atlassian.jira.issue.MutableIssue import java.sql.Timestamp; def issueManager = ComponentAccessor.getIssueManager() def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() MutableIssue mutableIssue = issueManager.getIssueObject(issue?.id); def priorityField = mutableIssue.priority int dueInDays = 0 String priorityname = priorityField.getName() if (priorityname == "Critical") { dueInDays = 1 } else if (priorityname == "High") { dueInDays = 5 } else if (priorityname == "Medium") { dueInDays = 20 } else if (priorityname == "Low") { dueInDays = 30 } else if (priorityname == "Lowest") { dueInDays = 0 } if( dueInDays > 0 ) { Date today = new Date(); Calendar MyDueDate = Calendar.getInstance(); MyDueDate.add(Calendar.DATE,dueInDays) while ([Calendar.SATURDAY, Calendar.SUNDAY].contains(MyDueDate.get(Calendar.DAY_OF_WEEK))) { MyDueDate.add(Calendar.DATE,1) } def dueTimestamp = new Timestamp(MyDueDate.getTimeInMillis()) mutableIssue.setDueDate(dueTimestamp) issueManager.updateIssue(user, mutableIssue, EventDispatchOption.ISSUE_UPDATED, false)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is't a possibility to the number of days added are only working day?
In fact when the Priority is, for example "Medium", we want to add 20 working days of the current date to set the due date. Not just 20 days and to be sure that the due date is not a not working day.
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.