How to do it...

Perform the following steps to set up a validator with custom-scripted logic:

  1. Select and edit the Simple Workflow.
  2. Select Diagram mode.
  3. Click on the Done global workflow transition.
  4. Click on the Validators link from the panel on the right-hand side.
  5. Click on Add validator, select Script Validator [ScriptRunner] from the list, and click on Add.
  6. Select the Simple scripted validator option.
  7. Enter the following script code in the Condition text box:
import com.opensymphony.workflow.InvalidInputException
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import org.apache.commons.lang3.StringUtils

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def solutionField = customFieldManager.getCustomFieldObjectByName("Solution Details")
def resolution = issue.getResolution().getName()
String solution = issue.getCustomFieldValue(solutionField)

if(resolution == "Done" && StringUtils.isBlank(solution)) {
false
} else {
true
}
  1. Enter You must provide the Solution Details if the Resolution is set to Done. in the Error field.
  2. Select Solution Details for Field.
  3. Click on the Add button to complete the validator setup.
  1. Click on Publish Draft to apply the change.

Your validator configuration should look something like the following screenshot:

Once we add our custom validator, the Groovy script will run every time the resolve issue transition is executed. If the Resolution field is set to Done and the Solution Details field is empty, we will get a message from the Error field, as shown in the following screenshot:

We will now see how these steps work.

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

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