Script Runner Set resolution to fixed after query

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

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 

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,

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

0 vote

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

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

365 views 0 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you