Jira scripted field value changing automatically

Problem:-

  • The ROI field in Jira is inconsistently set to "N" or blank (None) even though the issue summary contains "ROI".
  • The field sometimes toggles between "N" and None after page refreshes or automatically.

Script Behavior:

The script is designed to:

  1. Check if the issue type is Placement.
  2. Check if the ROI field is null.
  3. If the summary contains "ROI" (case-insensitive), set the ROI field to "Y"; otherwise, set it to "N"

Current Observations:

  • The ROI field is sometimes set to "N" even when the summary contains "ROI".
  • After refreshing the page, the ROI field sometimes changes from "N" to None or vice versa.

Attempted Fixes:

  1. Updated the script to use some instead of any for change log checks.
  2. Added case-insensitive checks for "ROI" in the summary.
  3. Added logging to track when and why the ROI field is updated.

Request for Help:

  • Why is the ROI field inconsistently set to "N" or None?
  • How can I ensure the ROI field 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”}
}

Hi ms_1991,
what kind of script is this “behavior” and when it is called?

coukd it be that you have more than one field with name ROI in “/rest/api/2/field” ?