Need Help With Validator Code!!

Aaron Andrade October 18, 2021

I have four check boxes that are called EMP Local Backup, User Share, Email Mailbox, and Email Forwarding. I have validators applied so that when any combination of the first three are checked it then makes the Date Field Retention End Date. If the Email Forwarding is the only one checked it will require Date Field Forwarding End Date. If any of the first three and the email forwarding are checked it requires both. 

My issue is that if I check any of the first three it is still requiring the the Forward End Date and if I only select Email Forwarding it is still requiring Retention End Date Field. Below is a screen shot of the code I have. I look forward to talking with you all.

image.png

1 answer

1 accepted

0 votes
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 20, 2021

Hi @Aaron Andrade

It would be best to use one Custom Script Validator instead of multiple Simple Scripted Validators for your requirement.

Below is an example working code for your reference:-

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.opensymphony.workflow.InvalidInputException

def mutableIssue = issue as MutableIssue

def customFieldManager = ComponentAccessor.customFieldManager
def notificationOptions = customFieldManager.getCustomFieldObjectsByName('Notification Options').first()

def originalDueDate = customFieldManager.getCustomFieldObjectsByName('Original Due Date').first()
def actualDeliveryDate = customFieldManager.getCustomFieldObjectsByName('Actual Delivery Date').first()

def notificationOptionsValue = mutableIssue.getCustomFieldValue(notificationOptions) as String
def originalDueDateValue = mutableIssue.getCustomFieldValue(originalDueDate)
def actualDeliveryDateValue = mutableIssue.getCustomFieldValue(actualDeliveryDate)

if(notificationOptionsValue == "[Email]") {
if(actualDeliveryDateValue != null) {
log.warn "===>>> Email Triggered"
} else {
throw new InvalidInputException("Actual Delivery Date Missing")
}
} else {
if(originalDueDateValue != null) {
log.warn "Others Triggered"
} else {
throw new InvalidInputException("Original Delivery Date Missing")
}
}

Please note, this sample code is not 100% exact to your environment. Hence, you will need to make the required modifications.

Below is a print screen of the validator configuration:-

validator_config.png

Also, I include a few test print screens for your reference:-

1) If the Email checkbox is selected and the  Actual Delivery Date is not filled in, the validation returns an Error

test1.png

2) The Email is selected, and the incorrect date is filled up, the validation returns an Error:-

test2.png

3) This works the same for the other Checkboxes, if the Telephone Call, Social Network or Post option is selected, and the Original Due Date is not filled in, the validator returns an error message:-

test3.png

4) If the Telephone Call, Social Network or Post option is selected and the incorrect date is selected, the validator will return an error message:-

test4.png

I hope this helps to answer your question. :)

 

Thank you and Kind Regards,

Ram

Aaron Andrade October 21, 2021

Thank you for your time and effort. This did complete successfully.

Suggest an answer

Log in or Sign up to answer