for defect Type: In PDS EDF schema, the Safety Relevant fields is mandatory

mummareddy supriya April 12, 2024

for defect Type: In PDS EDF schema, the Safety Relevant fields is mandatory, but it can hold the "Not evaluated "  but instead the system should not allow to progress the defect if the safety is chosen as "Not evaluated,basically, if the Safety relevant field is Not Evaluated, it should not allow the status change from analyzed to in progress.can any one suggest me how can i achieve it

1 answer

0 votes
mummareddy supriya April 12, 2024

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.status.Status
import com.atlassian.jira.workflow.JiraWorkflow

// Get the custom field "Safety"
CustomField safetyField = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Safety")

if (safetyField) {
// Get the issue by key
Issue issue = ComponentAccessor.issueManager.getIssueByCurrentKey("PET")

if (issue) {
// Get the value of the "Safety" field
def safetyValue = issue.getCustomFieldValue(safetyField)

if (safetyValue && safetyValue.toString().trim().equalsIgnoreCase("Not Evaluated")) {
// Get the current status
Status currentStatus = issue.getStatusObject()

// Check if the current status is 'Analyzed'
if (currentStatus.getName() == "Analyzed") {
// Log the current status
log.debug("Current Status: ${currentStatus.getName()}")

// Log a warning message and prevent transition if safety is 'Not Evaluated'
log.warn("Transition from Analyzed to In Progress is not allowed when Safety is set to Not Evaluated.")
log.warn("Transition not allowed.")
} else {
// Log an info message indicating the transition is allowed
log.info("Transition is allowed.")
}
} else {
// Log a message indicating why the transition is not allowed
log.warn("Transition to 'In Progress' not allowed. Safety is not set to 'Not Evaluated'.")
log.warn("Transition not allowed.")
}
} else {
log.info("Safety value found. Transition is allowed.")
}
} else {
// Log an error if the custom field is not found
log.error("Custom field 'Safety' not found.")
},i tried this script for singal ticket but i need to check it for all defect issues .so please guide to to achive it 

Suggest an answer

Log in or Sign up to answer