Hi,
I want to create a field check in a script runner behaviour.
When the field “duedate” is changed i want to validate:
1) if the new value is not in future > show error in GUI
2) if the new date is in future > okay
3) If the field is not changed, nothing should happen.
As far as i know i cannot use “issue” in behaviours, instead of it i must use "underlyingIssue".
To compare if a field was changed i use usualy the simple line:
issue.duedate != originalIssue.duedate
But i was not able to find something similar like "oiginalIsse" or "originalValue" for underlyingIssue. Is there anything similar i can use in behaviour?
Best Regards
Manuel
If you need to specifically query the value that's currently stored in the data base for the issue while in a behaviour, use the underlyingIssue like you would use the "issue" object present in many other scriptrunner areas.
For due date, you can use the field directly
def originalDueDate = underlyingIssue.duedate
For custom fields,
def originalCustomFieldValue= underlyingIssue.getCustomFieldValue(customField)
Then, you can compare those against the "formfield" value. Be sure to account for possible differences in data types and formats.
There isn't any such a thing as "originalIssue". What you get is the issue when the script is running.
The part that you think you need to do the comparison with 'if the field is not changed' - you don't need to, your script simply shouldn't be running at all in that situation.
See this example below:
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
/*
Needs to be attached to 'Due Date' system field
*/
final String ERROR_MESSAGE = "Due Date cannot be set in past/present."
FormField dueDateField = getFieldById(getFieldChanged())
Date dueDateValue = (Date) dueDateField?.getValue()
if (dueDateValue != null && dueDateValue.before(new Date())) {
dueDateField?.setValid(false)
dueDateField?.setError(ERROR_MESSAGE)
}
else {
dueDateField?.setValid(true)
dueDateField?.clearError()
}
It is attached to the Due Date field. It will only run when the field's value is being changed by the user (or when the field is being cleared, in which case it resets the field back to valid). I think this actually covers all the 3 requirements.
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.