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
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...

166 views 0 5
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