Verifies that the current user is equal to the value of a User custom field, in this case Sponsor.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.opensymphony.workflow.WorkflowContext

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def sponsorCf = customFieldManager.getCustomFieldObjectByName("Sponsor")

if (!sponsorCf) {
    log.warn("Failed to find Sponsor field on issue: ${issue.key}")
    passesCondition = false
    return
}

def sponsor = issue.getCustomFieldValue(sponsorCf) as ApplicationUser

if (!sponsor) {
    // Sponsor field has no value
    passesCondition = false
    return
}

String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller()
passesCondition = sponsor.name == currentUser

Have questions? Visit the Atlassian Community to connect, share, and learn with other Atlassian users and experts, including Adaptavist staff.

Ask a question about ScriptRunner for JIRA, Bitbucket Server, or Confluence.

Want to learn more? Check out courses on Adaptavist Learn, an online platform to onboard and train new users for Atlassian solutions.