Script Runner- Due date Set Up

Elif Alverson August 15, 2018

Hello, 

I am trying to write a script for script runner behaviors for the request below; 

If the Risk Level custom field is high, due date will be auto selected 7 days from ticket created

If the Risk Level custom field is medium, due date will be auto selected 30 days from ticket created

If the Risk Level custom field is low, due date will be auto selected 90 days from ticket created

I am not familiar with script writingas you can see and here is what I have came up with.

Could you please help me with it since it does not work?

 

 

def RiskLevelfield= getFieldByName("Risk Levels")

def DueDate = getFieldByName("Due Date")

 

def RiskLevel = RiskLevelfield.getValue() as RiskLevel

 

if (RiskLevel.name == "High") {

issue.setDueDate(new Timestamp((issue.dueDate + 7).time)) 

 

if (RiskLevel.name == "Medium") {

issue.setDueDate(new Timestamp((issue.dueDate + 30).time)) 

 

if (RiskLevel.name == "Low") {

issue.setDueDate(new Timestamp((issue.dueDate + 90).time)) 

 

}}}

 

else {

}

 

Thank you so much!

2 answers

1 vote
Roland Holban (Adaptavist)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 15, 2018

Create a behaviour on the "RiskLevel" field with the following server-side script:

def dueDateField = getFieldByName("Due Date")
def riskLevel = getFieldByName("Risk Levels").value

def dateToSet

if (riskLevel == "High") {
dateToSet = new Date() + 7
} else if (riskLevel == "Medium") {
dateToSet = new Date() + 30
} else if (riskLevel == "Low") {
dateToSet = new Date() + 90
}

dueDateField.setFormValue(dateToSet.format("dd/MMM/yy"))
Elif Alverson August 15, 2018

@Roland Holban (Adaptavist)

I have tried this on a test project by using Priority field instead of Risk Level and it does not work. Please see the screen shot below. Do you see anything wrong it?

Thank you.

image.png

Like Saitej Namburi likes this
Roland Holban (Adaptavist)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 15, 2018

Calling getValue() on the priority field actually returns a Priority object. So to use it like you want to you have to access its name property:

def priority = getFieldById("priority").value.name

Also, Im not sure why your field is called "Priority [System]", every time I've seen it was always just called "Priority"...

Like Dave Liao likes this
Elif Alverson August 20, 2018

@Roland Holban (Adaptavist)

Here is what I have tried and still nothing. Any ideas why?

Thank you for your patience and understanding.

Elif

image.png

Elif Alverson August 20, 2018

@Roland Holban (Adaptavist)

I also tried with a custom field called " SEVERITY" to see of it works. But it did not. Does it work on your system? We use Jira v7.11.2, not sure if that makes any difference.

image.png

Roland Holban (Adaptavist)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 20, 2018

What type of field is SEVERITY?

Elif Alverson August 20, 2018

It is " Select List (multiple choices)" .image.png

Roland Holban (Adaptavist)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 20, 2018

That should definitely work...

Is your behaviour mapped to the correct project/issue types? 

Like Dave Liao likes this
Elif Alverson August 20, 2018

I tried to add conditions , no change. I change the severity on the ticket several times but no values are being assigned to " due date" . Please see below screen shots. 

image.png

 

image.png

Like Zhuxin Wang likes this
Dave Liao
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 3, 2020

@Elif Alverson (and to anyone else running into this issue), use getFieldByID("duedate"). Due Date is a Jira system field, so you need to pull it by its ID.

0 votes
Inayat N April 4, 2022

Your sample script above works perfectly for my use case.  Just one question:  How do I add "business days" to the Due Date instead of standard days?  How do I add 7 business days (to exclude Saturday and Sunday)?

For example:

Current date = January 1st Monday. 

Current date + 7 days = Monday January 8th

Current date + 7 business days = Wednesday January 10th

Suggest an answer

Log in or Sign up to answer