I have the following Script Runner - Behaviours:
def dueDateField = getFieldByName("Fecha de entrega")
def dueDateField2 = getFieldByName("Due Date")
def riskLevel = getFieldByName("Risk Rating").getValue()
def dateToSet
if (riskLevel == "1. Critical") {
dateToSet = new Date() + 7
} else if (riskLevel == "2. High") {
dateToSet = new Date() + 30
} else if (riskLevel != "3. Medium") {
dateToSet = new Date() + 90
}else if (riskLevel != "3. Medium") {
dateToSet = new Date() + 180
}
dueDateField.setFormValue(dateToSet.format("dd/MMM/yy"))
dueDateField2.setFormValue(dateToSet.format("dd/MMM/yy"))
It works for custom field Fecha de Entrega, But not for Due Date field.
I can't find my error!!
I'm new with script runner.
Hi Marcela,
From your code, the main reason the Due Date field is not updating is because you are invoking it using getFieldByName i.e.
def dueDateField2 = getFieldByName("Due Date")
Because this is a system field, you should instead invoke the field by using the getFieldById i.e.
def dueDateField2 = getFieldById("duedate")
Another point, for system fields the name should be in lower case. If you notice above I am using getFieldById("duedate") the duedate is fully in lowercase.
Also, if you are trying to update the date, you should use milliseconds instead of days.
For the Behaviour configuration, since your value is depending on the change of the Risk Level field, it would be better to use a Server Side Behaviour configuration.
Below is a print screen of the same Server Side Behaviour configuration:-
Below is a sample code for your reference:-
import java.sql.Timestamp
def riskLevel = getFieldById(fieldChanged)
def riskLevelValue = riskLevel.value.toString()
def dueDateField = getFieldByName("Fecha de entrega")
def dueDateField2 = getFieldById("duedate")
def days = 24*60*60*1000 // number of milliseconds in a day
def updatedDate = new Date()
def timePeriod // to pass the number of days.
if (riskLevelValue == "1. Critical") {
timePeriod = 7
} else if (riskLevelValue == "2. High") {
timePeriod = 30
} else if (riskLevelValue == "3. Medium") {
timePeriod = 90
} else {
timePeriod = 180
}
updatedDate.setTime(new Timestamp(System.currentTimeMillis() + timePeriod * days).time)
dueDateField.setFormValue(updatedDate.format("dd/MMMM/yyyy"))
dueDateField2.setFormValue(updatedDate.format("dd/MMMM/yyyy"))
Hope this helps solve your question :)
Cheers,
Ram
Hi Marcela,
From your code, the main reason the Due Date field is not updating is because you are invoking it using getFieldByName i.e.
def dueDateField2 = getFieldByName("Due Date")
Because this is a system field, you should instead invoke the field by using the getFieldById i.e.
def dueDateField2 = getFieldById("duedate")
Another point, for system fields the name should be in lower case. If you notice above I am using getFieldById("duedate") the duedate is fully in lowercase.
Also, if you are trying to update the date, you should use milliseconds instead of days.
For the Behaviour configuration, since your value is depending on the change of the Risk Level field, it would be better to use a Server Side Behaviour configuration.
Below is a print screen of the same Server Side Behaviour configuration:-
Below is a sample code for your reference:-
import java.sql.Timestamp
def riskLevel = getFieldById(fieldChanged)
def riskLevelValue = riskLevel.value.toString()
def dueDateField = getFieldByName("Fecha de entrega")
def dueDateField2 = getFieldById("duedate")
def days = 24*60*60*1000 // number of milliseconds in a day
def updatedDate = new Date()
def timePeriod // to pass the number of days.
if (riskLevelValue == "1. Critical") {
timePeriod = 7
} else if (riskLevelValue == "2. High") {
timePeriod = 30
} else if (riskLevelValue == "3. Medium") {
timePeriod = 90
} else {
timePeriod = 180
}
updatedDate.setTime(new Timestamp(System.currentTimeMillis() + timePeriod * days).time)
dueDateField.setFormValue(updatedDate.format("dd/MMMM/yyyy"))
dueDateField2.setFormValue(updatedDate.format("dd/MMMM/yyyy"))
Hope this helps solve your question :)
Cheers,
Ram
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.