Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Scriptrunner Behaviour date2 should be superior to date1

Mickaël Orsolino
Contributor
June 11, 2020

Hi,

 

I try to have a behaviour who block ticket creation/Edition if a date2 (Ending date) is inferior to date1 (Starting date).

 

I use the following code but It look like working during few day. 

import groovy.transform.BaseScript

def startDateField = getFieldByName("onCall start date")
def startDateValue = startDateField.getValue() as Date
def dueDateField = getFieldByName("onCall end date")
def dueDateValue = dueDateField.getValue() as Date

startDateField.clearError()
dueDateField.clearError()
strErrorText = "onCall end date must be greater than onCall start date"

if (dueDateValue != null && startDateValue != null ){
if(startDateValue > dueDateValue){
startDateField.setError(strErrorText)
dueDateField.setError(strErrorText)
}
}

 

Some user are complaining because they can't validate the ticket with correct date (Date2 was superior to date1). I think I have done something wrong.

Could you help me?

 

Regards,

Mickael O.

1 answer

0 votes
Leo
Community Champion
June 11, 2020

Hi @Mickaël Orsolino,

If I understood correctly your script does not validate the fields all the time as expected

if so, it matters what field you mapped with script(I believe you placed this as server side script). because script will be executing whenever the associated field is updated/changed

 

e.g.: you mapped this script with Date2 then

 I updated Date2 first (script runs here and found Date1 is empty so doesn't validate anything)

 then I update Date1(script won't be executing again)

 

To avoid this issue. create one more behaviour and map it to Date1 with same script

 

BR,

Leo 

Mickaël Orsolino
Contributor
June 30, 2020

Thank you Leo. I'll try it and I come back to you.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.5.1
TAGS
AUG Leaders

Atlassian Community Events