Script Runner Set resolution to fixed after query

Thomas Landuyt March 29, 2016

Hi,

 

today i created a escalation service in Script runner to update some custom fields.

 

import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.util.IssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.link.IssueLink;
def issueLinkManager = ComponentManager.getInstance().getIssueLinkManager()
def customFieldManager = ComponentManager.getInstance().getCustomFieldManager();
def cfEst1 = customFieldManager.getCustomFieldObject("customfield_13233");
def cfEst2 = customFieldManager.getCustomFieldObject("customfield_13234");
def cfEst3 = customFieldManager.getCustomFieldObject("customfield_13235");
def cfEst4 = customFieldManager.getCustomFieldObject("customfield_13236");
def cfEst5 = customFieldManager.getCustomFieldObject("customfield_13237");
def cfEstUncategorized = customFieldManager.getCustomFieldObject("customfield_13238");
def ticket = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_13621");
def changeHolder = new DefaultIssueChangeHolder();
double totalRemaining = 0;
for(IssueLink link in issueLinkManager.getInwardLinks(issue.id)){
 if (link.issueLinkType.name == "Epic Link")
    {
        def linkedIssue = link.sourceObject;
        def total = 0;
        if ( cfEst1 && linkedIssue.getCustomFieldValue(cfEst1)!=null)
          total = total + linkedIssue.getCustomFieldValue(cfEst1);
  if ( cfEst2 && linkedIssue.getCustomFieldValue(cfEst2)!=null)
       total +=  linkedIssue.getCustomFieldValue(cfEst2);   
        if ( cfEst3 && linkedIssue.getCustomFieldValue(cfEst3)!=null)       
           total +=  linkedIssue.getCustomFieldValue(cfEst3);
        if ( cfEst4 && linkedIssue.getCustomFieldValue(cfEst4)!=null)  
           total +=  linkedIssue.getCustomFieldValue(cfEst4);
        if ( cfEst5 && linkedIssue.getCustomFieldValue(cfEst5)!=null)
           total +=  linkedIssue.getCustomFieldValue(cfEst5);
         if ( cfEstUncategorized && linkedIssue.getCustomFieldValue(cfEstUncategorized)!=null)
           total += linkedIssue.getCustomFieldValue(cfEstUncategorized);
  
           totalRemaining += total;
     }
}
if ( issue.issueType.name == "Epic" ){
issue.setCustomFieldValue(ticket, totalRemaining);
ticket.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(ticket), totalRemaining), changeHolder);
}
Now i see when this query has run successfully then the resolution is put to Fixed without doing anything.
The action is all not filled in in the escalation service. Somebody who knows the reason?
kr,

3 answers

1 accepted

1 vote
Answer accepted
Vasiliy Zverev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 29, 2016

I am not sure, but it could be caused by specific of ModifiedValue object.

I usually use IssueManager.updateIssue() for issue update and never get such troubls https://docs.atlassian.com/jira/latest/com/atlassian/jira/issue/IssueManager.html 

0 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 29, 2016

You're saying there is no action set, but the resolution changes to Fixed, and the issue is not transitioned?

0 votes
Thomas Landuyt March 29, 2016

Hi ,

I tested your recommandation. but it doesn't help

 

import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.util.IssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.event.type.EventDispatchOption;
def issueManager = ComponentManager.getInstance().getIssueManager();
def issueLinkManager = ComponentManager.getInstance().getIssueLinkManager()
def customFieldManager = ComponentManager.getInstance().getCustomFieldManager();
def cfEst1 = customFieldManager.getCustomFieldObject("customfield_13233");
def cfEst2 = customFieldManager.getCustomFieldObject("customfield_13234");
def cfEst3 = customFieldManager.getCustomFieldObject("customfield_13235");
def cfEst4 = customFieldManager.getCustomFieldObject("customfield_13236");
def cfEst5 = customFieldManager.getCustomFieldObject("customfield_13237");
def cfEstUncategorized = customFieldManager.getCustomFieldObject("customfield_13238");
def ticket = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_13621");
def user = ComponentAccessor.userUtil.getUserObject("QA");
    def changeHolder = new DefaultIssueChangeHolder();
double totalRemaining = 0;
for(IssueLink link in issueLinkManager.getInwardLinks(issue.id)){
 if (link.issueLinkType.name == "Epic Link")
    {
        def linkedIssue = link.sourceObject;
        def total = 0;
        if ( cfEst1 && linkedIssue.getCustomFieldValue(cfEst1)!=null)
          total = total + linkedIssue.getCustomFieldValue(cfEst1);
  if ( cfEst2 && linkedIssue.getCustomFieldValue(cfEst2)!=null)
       total +=  linkedIssue.getCustomFieldValue(cfEst2);   
        if ( cfEst3 && linkedIssue.getCustomFieldValue(cfEst3)!=null)       
           total +=  linkedIssue.getCustomFieldValue(cfEst3);
        if ( cfEst4 && linkedIssue.getCustomFieldValue(cfEst4)!=null)  
           total +=  linkedIssue.getCustomFieldValue(cfEst4);
        if ( cfEst5 && linkedIssue.getCustomFieldValue(cfEst5)!=null)
           total +=  linkedIssue.getCustomFieldValue(cfEst5);
         if ( cfEstUncategorized && linkedIssue.getCustomFieldValue(cfEstUncategorized)!=null)
           total += linkedIssue.getCustomFieldValue(cfEstUncategorized);
  
           totalRemaining += total;
     }
}
if ( issue.issueType.name == "Epic" ){
issue.setCustomFieldValue(ticket, totalRemaining);
issueManager.updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED ,false);  
}
kr,
Vasiliy Zverev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 30, 2016

Perhaps you have some listener on update event which do such update?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events