Here a little example of how to validate 3 user fields to check they have different members selected. This example works in Jira Server & Datacenter with Scriptrunner or MyGroovy Apps.

Note: InvalidInputException must be raised to “Stop” the Transition.

import com.atlassian.jira.component.ComponentAccessor;
import com.opensymphony.workflow.InvalidInputException

def linemanager =  ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName("Line Manager");
def teambuddy = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName("Assigning a Team buddy");
def socialbuddy = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName("Assigning a Social buddy");

def user = issue.getCustomFieldValue(linemanager[0])?.getUsername();
def user2 = issue.getCustomFieldValue(teambuddy[0])?.getUsername();
def user3 = issue.getCustomFieldValue(socialbuddy[0])?.getUsername();

log.warn "Line Manager: " + user + " Team Buddy: " + user2 + " Social Buddy: " + user3

if( user != user2 && user2 != user3 && user3 != user ) { 
    log.warn "return OK!"
} else {
    log.warn "return KO"
    throw new InvalidInputException("Validation Error: Line Manager, Social Buddy and Team Buddy must be different persons.")    
}

By MrAddon

.

Posted by:.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s