# Jira scripted field value changing automatically

**URL:** <https://forum.library.adaptavist.com/t/jira-scripted-field-value-changing-automatically/556>\
**Category:** Scripts\
**Tags:** jira, listener\
**Created:** [January 24, 2025, 11:56am UTC](https://forum.library.adaptavist.com/t/jira-scripted-field-value-changing-automatically/556 "2025-01-24T11:56:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ms\_1991](https://avatars.discourse-cdn.com/v4/letter/m/6de8d8/32.png) [@ms\_1991](https://forum.library.adaptavist.com/u/ms_1991)\
**Post date:** [January 24, 2025, 11:56am UTC](https://forum.library.adaptavist.com/t/jira-scripted-field-value-changing-automatically/556/1 "2025-01-24T11:56:52Z")

</div>

**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”}  
}

---

<div class="post-metadata">

**Author:** ![nikolayr](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.library.adaptavist.com/nikolayr/32/254_2.png) [@nikolayr](https://forum.library.adaptavist.com/u/nikolayr)\
**Post date:** [January 28, 2025, 8:48pm UTC](https://forum.library.adaptavist.com/t/jira-scripted-field-value-changing-automatically/556/2 "2025-01-28T20:48:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nikolayr](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.library.adaptavist.com/nikolayr/32/254_2.png) [@nikolayr](https://forum.library.adaptavist.com/u/nikolayr)\
**Post date:** [January 28, 2025, 8:51pm UTC](https://forum.library.adaptavist.com/t/jira-scripted-field-value-changing-automatically/556/3 "2025-01-28T20:51:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/adaptavistlibrary/original/1X/ceb18adf14fa58b4c6de03aa69ada8b07359620c.png) [@system](https://forum.library.adaptavist.com/u/system)\
**Post date:** [July 27, 2025, 8:51pm UTC](https://forum.library.adaptavist.com/t/jira-scripted-field-value-changing-automatically/556/4 "2025-07-27T20:51:35Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
