Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

Script Runner- Due date Set Up Edited

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!

1 answer

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

@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

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

@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

@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

What type of field is SEVERITY?

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

That should definitely work...

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

Like Dave Liao likes this

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 Nov 03, 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.

Suggest an answer

Log in or Sign up to answer
TAGS

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