I have a requirement to check that at least one of five date/time custom fields on the screen has a value. If all five are empty, I need to stop the transition until at least one date field has a value. To make things more complicated, if the first field has a value, then the other four fields should be empty. And if any one of the four fields has a value, then the first field must be empty.
So,
if date fields 1-5 are empty, require at least one field AND
if date1 has a value dates 2-5 need to be blank
If any of dates 2-5 has a value, date 1 needs to be blank.
I'm really struggling to just determine if a date/time field has a null value. Using Behaviours, I tried the below checking if reqdateField or reqdateVal was null and that doesn't work. I also tried (!reqdateField) and (!reqdateVal) and that didn't work. Any ideas? If I can figure out how to check for a null value, I can probably come up with figuring out the combinations of fields. This is for Jira Data Center.
From your description, you are trying to determine if at least one of the fields has a value; for this case, you will need to create 5 Server-Side Behaviours, i.e. one for each field.
You should update your code to:-
1) For the Requested Release Date/Time field's Server-Side Behaviour Code:-
def reqdateField = getFieldById(fieldChanged)
def reqdateVal = reqdateField.value as String
def p1 = getFieldByName('P1 Release Date/Time')
def p1Value = p1.value as String
def p2 = getFieldByName('P2 Release Date/Time')
def p2Value = p2.value as String
def p3 = getFieldByName('P3 Release Date/Time')
def p3Value = p3.value as String
def p4 = getFieldByName('P4 Release Date/Time')
def p4Value = p4.value as String
reqdateField.clearError()
if (!reqdateVal && !p1Value && !p2Value && !p3Value && !p4Value ){
reqdateField.setError('Please provide Requested Date or one or more Phased Release dates.')
}
2) For P1 Field's Server-Side Behaviour code:-
def reqdateField = getFieldByName('Requested Release Date/Time ')
def reqdateVal = reqdateField.value as String
def p1 = getFieldById(fieldChanged)
def p1Value = p1.value as String
def p2 = getFieldByName('P2 Release Date/Time')
def p2Value = p2.value as String
def p3 = getFieldByName('P3 Release Date/Time')
def p3Value = p3.value as String
def p4 = getFieldByName('P4 Release Date/Time')
def p4Value = p4.value as String
reqdateField.clearError()
if (!reqdateVal && !p1Value && !p2Value && !p3Value && !p4Value ){
reqdateField.setError('Please provide Requested Date or one or more Phased Release dates.')
}
3) For P2 Field's Server-Side Behaviour code:-
def reqdateField = getFieldByName('Requested Release Date/Time ')
def reqdateVal = reqdateField.value as String
def p1 = getFieldByName('P1 Release Date/Time')
def p1Value = p1.value as String
def p2 = getFieldById(fieldChanged)
def p2Value = p2.value as String
def p3 = getFieldByName('P3 Release Date/Time')
def p3Value = p3.value as String
def p4 = getFieldByName('P4 Release Date/Time')
def p4Value = p4.value as String
reqdateField.clearError()
if (!reqdateVal && !p1Value && !p2Value && !p3Value && !p4Value ){
reqdateField.setError('Please provide Requested Date or one or more Phased Release dates.')
}
4) For P3 Field's Server-Side Behaviour code:-
def reqdateField = getFieldByName('Requested Release Date/Time ')
def reqdateVal = reqdateField.value as String
def p1 = getFieldByName('P1 Release Date/Time')
def p1Value = p1.value as String
def p2 = getFieldByName('P2 Release Date/Time')
def p2Value = p2.value as String
def p3 = getFieldById(fieldChanged)
def p3Value = p3.value as String
def p4 = getFieldByName('P4 Release Date/Time')
def p4Value = p4.value as String
reqdateField.clearError()
if (!reqdateVal && !p1Value && !p2Value && !p3Value && !p4Value ){
reqdateField.setError('Please provide Requested Date or one or more Phased Release dates.')
}
5) For P4 Field's Server-Side Behaviour code:-
def reqdateField = getFieldByName('Requested Release Date/Time ')
def reqdateVal = reqdateField.value as String
def p1 = getFieldByName('P1 Release Date/Time')
def p1Value = p1.value as String
def p2 = getFieldByName('P2 Release Date/Time')
def p2Value = p2.value as String
def p3 = getFieldByName('P3 Release Date/Time')
def p3Value = p3.value as String
def p4 = getFieldById(fieldChanged)
def p4Value = p4.value as String
reqdateField.clearError()
if (!reqdateVal && !p1Value && !p2Value && !p3Value && !p4Value ){
reqdateField.setError('Please provide Requested Date or one or more Phased Release dates.')
}
Using the approach above, when either one of the fields has a value, it will create/edit the issue. Otherwise, when all the fields are empty, it will return an error message.
Also, if you observe in the sample codes that I have provided above, in each of the examples, I have declared the field the Server-Side Behaviour is configured for using:-
getFieldById(fieldChanged)
This ensures that the Behaviour will trigger only when that particular field is updated.
I hope this helps to solve your question. :-)
Thank you and Kind regards,
Ram
Hello @Ram Kumar Aravindakshan _Adaptavist_ , thank you for the suggested code. I implemented everything as suggested. The problem is that when all the fields are empty, the transition is not stopped with an error. This has been my issue. The code looks correct but for whatever reason, the transition is not stopped. I need the error popup to trigger but it won't. Could it be that no field has changed so it doesn't trigger anything? If I bring up the screen and the fields are all blank and I try to transition the ticket with all the fields blank, then technically, nothing has changed...??? Or does field changed refer to the field selected in the Behaviour regardless if it changes or not?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Could you please share screenshots of all your Behaviour configurations you are using for this requirement.
I am asking this so I can review it and provide some feedback.
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Were you able to solve this?
If not as requested in my previous comment, could you please share the screenshots of all your Behaviour configurations.
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You will need to check the values of the fields P1 -4
I can see you do this to get the reqDateVal
def reqdateVal = reqdateField.getValue()
You'll also need to get the values for the other fields.
e.g.
def p1 = getFieldByName("P1 Release Date/Time").getValue()
if getFieldByName("P1 Release Date/Time") is likely to return null and not allow you to getValue()
try
def p1 = getFieldByName("P1 Release Date/Time")? getFieldByName("P1 Release Date/Time").getValue() : null
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.