ScriptRunner Escalation Service to append value to custom field

Hi, due to the inability of the Bulk Edit operation to append to custom fields I am trying to implement a script to run in the ScriptRunner Escalation Service to do the appending based on a JQL query.

The logs show that the issues are being updated but when i look at the issue in JIRA it has not been updated.

Am I missing a commit, store or reindex? Here is my script -

def componentManager = ComponentManager.getInstance()
def FoundinRel = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Found in Release'}
def optionsProgManager = componentManager.getComponentInstanceOfType(OptionsManager.class)
if(FoundinRel!=null)
{
log.debug("DOING UPDATE")
log.debug("$issue")
def fieldConfig = FoundinRel.getRelevantConfig(issue)
def option = optionsProgManager.getOptions(fieldConfig).find {it.value == 'CD-6.4.4'}
def currentOptions = issue.getCustomFieldValue(FoundinRel) ?: []
issue.setCustomFieldValue(FoundinRel, currentOptions + [option])
log.debug("Original Options = $currentOptions")
log.debug("New Option = $option")
def updatedOptions = issue.getCustomFieldValue(FoundinRel) ?: []
log.debug("Updated Options = $updatedOptions")
}

 

Logfile -

2015-11-03 10:30:02,943 http-bio-8080-exec-9 DEBUG mccooyc487 630x1251x1 qp4lch 10.168.40.75,127.0.0.1 /rest/scriptrunner/latest/canned/com.onresolve.scriptrunner.canned.jira.admin.EscalationService/preview [DEBUG] DOING UPDATE
2015-11-03 10:30:02,943 http-bio-8080-exec-9 DEBUG mccooyc487 630x1251x1 qp4lch 10.168.40.75,127.0.0.1 /rest/scriptrunner/latest/canned/com.onresolve.scriptrunner.canned.jira.admin.EscalationService/preview [DEBUG] PAM-720
2015-11-03 10:30:02,946 http-bio-8080-exec-9 DEBUG mccooyc487 630x1251x1 qp4lch 10.168.40.75,127.0.0.1 /rest/scriptrunner/latest/canned/com.onresolve.scriptrunner.canned.jira.admin.EscalationService/preview [DEBUG] Original Options = [CD-3.2.1]
2015-11-03 10:30:02,946 http-bio-8080-exec-9 DEBUG mccooyc487 630x1251x1 qp4lch 10.168.40.75,127.0.0.1 /rest/scriptrunner/latest/canned/com.onresolve.scriptrunner.canned.jira.admin.EscalationService/preview [DEBUG] New Option = CD-6.4.4
2015-11-03 10:30:02,946 http-bio-8080-exec-9 DEBUG mccooyc487 630x1251x1 qp4lch 10.168.40.75,127.0.0.1 /rest/scriptrunner/latest/canned/com.onresolve.scriptrunner.canned.jira.admin.EscalationService/preview [DEBUG] Updated Options = [CD-3.2.1, CD-6.4.4]

 

The log file suggests the issue has been updated by what is returned in $UpdatedOptions but this is not reflected in the JIRA issue.

 

What am i doing wrong?

 

Thanks

Conor

 

 

1 answer

Hi Conor,

Try to replace issue.setCustomFieldValue(FoundinRel, currentOptions + [option])

with 

 

def fieldLayoutItem =
fieldLayoutManager.getFieldLayout(myIssue).getFieldLayoutItem(FoundinRel);
def issueChangeHolder = new DefaultIssueChangeHolder();
FoundinRel.updateValue(fieldLayoutItem, myIssue,
new ModifiedValue(currentOptions, currentOptions + [option]), issueChangeHolder);

PS You can also use ComponentAccessor to access the managers.

ex: 

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsProgManager = ComponentAccessor.getOptionsManager()
def fieldLayoutManager = ComponentAccessor.getFieldLayoutManager()

Please let me know if this helps you.

Regards 

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Friday in Jira Service Desk

Looking for anyone who has switched from Zendesk to Jira Service Desk

Hi Community! The Jira Service Desk marketing team is looking for customers who have successfully switched from Zendesk to Jira Service Desk!   We’d love to hear your thoughts on the pros and ...

117 views 7 3
Join discussion

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