How it works...

The Script Validator works just like any other validator, except that we can define our own validation logic using Groovy scripts. So, let's go through the script, and see what it does.

We first get the Solution Details custom field via its name, as shown in the following line of code. If you have more than one custom field with the same name, you need to use its ID instead of its name:

def solutionField = customFieldManager.getCustomFieldObjectByName("Solution Details")

We then select the resolution value and obtain the value entered for Solution Details during the transition, as follows:

def resolution = issue.getResolutionObject().getName() 
String solution = issue.getCustomFieldValue(solutionField) 

In our example, we check the resolution name; we can also check the ID of the resolution by changing getName() to getId().

If you have multiple custom fields with the same name, use getId().

Lastly, we check whether the Resolution value is Done and the Solution Details value is blank. In this case, we return a value of false, so the validation fails. All other cases will return the value true, so the validation passes. We also use StringUtils.isBlank(solution) to check for blank values so that we can catch cases when users enter empty spaces for the Solution Details field.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.161.180