I would like to expose and require a "Reason" custom text field when the "Due Date" field is changed from the original value. Does anyone know the proper syntax?
Doing a bit of digging for older unanswered questions and found this one...
Behaviours can't "expose" a field ... you have to add the Reason field to your edit (or transition) screens first.
Then, you can use behaviours to hide the Reason field by default, but run a script when the Due Date is changed that will trigger the Reason field to be displayed and flagged as required
One trick though... you might want to cancel the changes if the user realizes this and want to just set back the original due date (rather than close the form and potentially lose other edits).
So the script has to detect when the field is changed, and when it's actually different than the stored value.
Something along these lines should work (add to the due date field server-side script in behaviors)
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
if(!underlyingIssue) return //nothing to do when creating (there is no stored issue yet)
def dueDateField = getFieldById(fieldChanged)
def reasonFld = getFieldByName('Reason')
def showReason = underlyingIssue.dueDate && underlyingIssue.dueDate != dueDateField.value
reasonFld.setHidden(!showReason).setRequired(showReason)
if(!showReason){
//clear out the reason field if we're hiding it so we don't actually submit a reason for change when we've changed out mind and not making the change
reasonFld.setFormValue(null)
}
The top 3 lines are not needed (but won't hurt anything) if you store the script "in-line". They are helpful however if you store your script as a file. This will help compilation in the script editor or external IDE.
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.