User Tools

Site Tools


conditions

Scripted Conditions

Following scripts can be used for scripted conditions within the workflow

Only specific users will have access to this workflow step

currentUser.name in ["USERID1","USERID2"]

Only if Version 2.0 not in Fix Version field

!("Version 2.0" in issue.fixVersions*.name)

Only return true if we have "Awaiting Approval" in field Approval Stats and therefore display transition

import com.atlassian.jira.component.ComponentAccessor
 
//Define Custom Field Manager
def cfm = ComponentAccessor.getCustomFieldManager()
//get field object
def cfApprovalStatus = cfm.getCustomFieldObjectByName("Approval Status")
def cfApprovalStatusValue = issue.getCustomFieldValue(cfApprovalStatus)
//check if the field is equal to Awaiting Approval
if (cfApprovalStatusValue == "Awaiting Approval"){
    //Returned true in comparison
    return true
}

Only allow transition if none of the values in custom fields are "Awaiting Approval"

import com.atlassian.jira.component.ComponentAccessor
 
//Define cfm
def cfm = ComponentAccessor.getCustomFieldManager()
//get field object
def cfFirstApprovalStatus = cfm.getCustomFieldObjectByName("First Approval Status")
def cfFirstApprovalStatusValue = issue.getCustomFieldValue(cfFirstApprovalStatus)
def cfSecondApprovalStatus = cfm.getCustomFieldObjectByName("Second Approval Status")
def cfSecondApprovalStatusValue = issue.getCustomFieldValue(cfSecondApprovalStatus)
 
if ((cfFirstApprovalStatusValue != "Awaiting Approval")&&(cfSecondApprovalStatusValue != "Awaiting Approval"){
    //Returned true in comparison
    return true
}

Allow only if user is member of role "Developers" in project OR "My Field" has value of "Field Value"

import com.atlassian.jira.component.ComponentAccessor 
 
def selectedMyField = cfValues['My Field'].toString()
 
 
def userUtil = ComponentAccessor.getUserUtil()
 
    isUserMemberOfRole("Developers") || selectedMyField.equals("Field Value")
 
 
conditions.txt · Last modified: 2018/04/13 10:39 by root