Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Using a Workflow Condition

Rasool
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 18, 2024

Listener:

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.CustomFieldManager
import org.apache.log4j.Logger

def log = Logger.getLogger("com.acme.jira")
def customFieldManager = ComponentAccessor.getComponent(CustomFieldManager)
def issue = event.issue as Issue

def customFieldId = "customfield_12345"  // Replace with your actual custom field ID
def customField = customFieldManager.getCustomFieldObject(customFieldId)
def customFieldValue = issue.getCustomFieldValue(customField)

if (!customFieldValue) {
    log.warn("The custom field is empty for issue ${issue.key}. Further actions cannot proceed.")
   
    // Block the action by throwing an exception
    throw new IllegalStateException("Action blocked: Cannot proceed as the custom field is empty.")
} else {
       log.info("The custom field is filled for issue ${issue.key}. Actions can proceed.")
}
**********************************************************************************************

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue

// Get the custom field by ID
def customFieldId = "customfield_12345" // Replace with your custom field ID
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(customFieldId)
def customFieldValue = underlyingIssue.getCustomFieldValue(customField)

// Get the Behaviour's field (the field that triggers the action, such as the approval button or transition)
def approvalField = getFieldByName("Approval Field") // Replace with the name of the field you want to control

if (!customFieldValue) {
    // Block or disable the approval action (make the field readonly or hidden)
    approvalField.setReadOnly(true)
   
} else {
    // Allow the approval field to be editable if the custom field is filled
    approvalField.setReadOnly(false)
}

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events