Problem:-
- The
ROIfield in Jira is inconsistently set to"N"or blank (None) even though the issue summary contains"ROI". - The field sometimes toggles between
"N"andNoneafter page refreshes or automatically.
Script Behavior:
The script is designed to:
- Check if the issue type is
Placement. - Check if the
ROIfield isnull. - If the summary contains
"ROI"(case-insensitive), set theROIfield to"Y"; otherwise, set it to"N"
Current Observations:
- The
ROIfield is sometimes set to"N"even when the summary contains"ROI". - After refreshing the page, the
ROIfield sometimes changes from"N"toNoneor vice versa.
Attempted Fixes:
- Updated the script to use
someinstead ofanyfor change log checks. - Added case-insensitive checks for
"ROI"in the summary. - Added logging to track when and why the
ROIfield is updated.
Request for Help:
- Why is the
ROIfield inconsistently set to"N"orNone? - How can I ensure the
ROIfield is set correctly based on the summary? - Are there any conflicts or race conditions in the script or other automations?
SCRIPT:
// Create ROI field in ■■■■
// Bahaviour adjusted to only make the field visible
import groovy.json.JsonSlurper
// Initialize Json to later parse the response
def jsonSlurper = new JsonSlurper()
// Get the issue
def issue = issue.key
def issueResp = get(“/rest/api/2/issue/${issue}”)
.asString()
assert issueResp.status == 200
// Parse the response
def json = jsonSlurper.parseText(issueResp.body)
// Retrieve issue type
def issueType = json.fields.issuetype.name as String
def summary = json.fields.summary.substring(0,3) as String
// Function to retrieve the custom field identifier based on the name of the field
def getCustomFieldId(customFieldName){
def jsonSlurper = new JsonSlurper()
def fieldsData = get(“/rest/api/2/field”).asString()
def fields = jsonSlurper.parseText(fieldsData.body)
def customFieldId = fields.find { it.name == customFieldName }.id
return customFieldId as String
}
// Get ROI field id
roiFieldId = getCustomFieldId(“ROI”)
// If issue type is Placement then check if the “ROI” string is
// present in the summary if yes return Y in the ROI field
// else return N
if(issueType == “Placement” && json.fields.“${roiFieldId}” == null) {
if(“ROI” in summary){ return “Y”}
else{return “N”}
}