Forums

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

Script runner behaviour question to avoid running it on form load where there are no changes

saravanan subramanian
Contributor
July 1, 2025

Hi TEam,

 

I have the code below to set the field "Severity Update Flag" when there are changes to the  field "PSIT Severity"  , how ever behavior below fires even when there is no change to the field PSIT Severity just when we click the edit button is there a way to avoid it?

Please let me know

 

 

 

 

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issue = underlyingIssue
def tgtField = customFieldManager.getCustomFieldObjects(issue).find {it.name == "PSIT Severity"}

// Get a pointer to both my fields
def demoSelect = getFieldByName("PSIT Severity")
def demoMultiTxt = getFieldByName("Severity Update Flag")

// Get the Value of the Select List Field
def selectedVal = demoSelect?.getValue()
def previousVal = tgtField?.getValue(issue)

if (selectedVal != null){
if (selectedVal?.toString()?.equalsIgnoreCase(previousVal?.toString())) {
    log.debug("Values are the same I will set the Val to False")
                String val ="False"
    demoMultiTxt?.setFormValue(val)
} else {
    log.debug("Values are different I will set the Val to True")
                String val ="True"
                demoMultiTxt?.setFormValue(val)
   
}
}

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
July 7, 2025

Hi @saravanan subramanian

Upon reviewing your code, I can confirm the Behaviour is working as expected.

You seem to be trying to obtain the previous field value. Please confirm if this is your goal.

If yes, then the approach you are taking will not work. For this, you must use the ChangeHistory object.

For more information on how the ChangeHistory object is used, you can refer to this ScriptRunner Library example code.

Let me know if you need further assistance and I will try to provide a working sample.

Thank you and Kind regards,
Ram

 

saravanan subramanian
Contributor
July 7, 2025

Hi Ram,

Thank you for the feedback.  We need to change the flag if there is any change in the selected field. Thank you for your suggestion of using "changehistory" object  - will it fire immediately when the value is changed or do we need to save the record in order to get the contents from the "changehistory" object ? .  Please let me know.

Can you please give me an working example also?

 

 

TAGS
AUG Leaders

Atlassian Community Events