Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Change the due date based on priority field

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.

3 answers

1 accepted

0 votes
Answer accepted

Hi @Stéphane Eursels

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

Fine it's work.

Thank's.

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)
}

 

Prakash I'm New Here May 19, 2021

@Stéphane Eursels  Thanks! This helped me to fulfil our user requirement! (y)

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.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
Community showcase
Published in Jira Service Management

JSM June Challenge #2: Share how your business teams became ITSM rockstars

For JSM June Challenge #2, share how your non-technical teams like HR, legal, marketing, finance, and beyond started using Jira Service Management! Tell us: Did they ask to start using it or...

172 views 6 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you