Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,368,355
Community Members
 
Community Events
168
Community Groups

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

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

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

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