Groovy Script won't update Issue history for Custom Number Field

Adam Holloway August 15, 2022

I'm stumped. I've a found few posts and checked out the Adaptavist library but I just can't the issue history to update. Instead, it throws an error for

 

EventDispatchOption where all the code examples I've seen read as if it should work. This script is running within a ScriptRunner scripted field. I want it to  update another value (Custom Number Field) before returning the scripted field value.
The Error:
2022-08-15 18:06:33,897 ERROR [customfield.GroovyCustomField]: Script field failed on issue: (XXX-13 field: Unused groovy.lang.MissingPropertyException: No such property: EventDispatchOption for class: Script1040 at Script1040.run(Script1040.groovy:80)

 

The ResScoreField is the custom number field I want change history captured for. I do some other comparisons with issue fields but those work (not shown) so to simplify I just want to record in the issue history when the value of the ResScoreField changes from 1 to 2. Both the scripted field and custom Number field update on the ticket as expected but the ResScoreField never writes to the history. 

Simplified Script:

 

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.ModifiedValue;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;
import com.atlassian.jira.issue.UpdateIssueRequest;
import com.atlassian.jira.event.*

 

def changeHolder = new DefaultIssueChangeHolder();
def MyissueManager = ComponentAccessor.getIssueManager();
def ResScoreField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_16100";
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
    
def NewValue = 2.0;
def CurScore = 1.0;

    ResScoreField.updateValue(null,issue, new ModifiedValueCurScore, NewValue), changeHolder);
   
    MyissueManager.updateIssue(user,issue,EventDispatchOption.ISSUE_UPDATED,false);

2 answers

1 accepted

0 votes
Answer accepted
Florian Bonniec
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 15, 2022

Hi @Adam Holloway 

You should not update issue in a scriptfield as it's run everytime you display the issue, use a script listener instead.

 

If issueManager do not add entry in the issueHistory, updating using issueService should.

https://docs.atlassian.com/software/jira/docs/api/7.6.1/com/atlassian/jira/bc/issue/IssueService.html

 

https://library.adaptavist.com/entity/update-the-priority-of-an-issue-in-jira

 

Regards

0 votes
Adam Holloway August 16, 2022

Ok. Makes sense.  I will move what I am trying to do over to a Listener instead. Cheers, thx.

Suggest an answer

Log in or Sign up to answer