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!
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"))
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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"...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here is what I have tried and still nothing. Any ideas why?
Thank you for your patience and understanding.
Elif
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What type of field is SEVERITY?
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.
That should definitely work...
Is your behaviour mapped to the correct project/issue types?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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.