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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.