Hello everybody. I try to make Script Listener, which in the time of issue creation make a Issue in another instance of jira via REST and I want to parse response to get ID of created issue and set that ID in to custom field, but I can't. Is it possible to set value in custom field via script listener when Issue Create event happens?
def issue = event.getIssue()
def key = issue.key
MutableIssue mI = ComponentAccessor.getIssueManager().getIssueByCurrentKey(key)
mI.setCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Issue ID"),"here is ID from response")
And why I can't use this
def issue = event.getIssue()
issue.setCustomFieldValue(cF, value)
Hi
1) event.issue returns "Issue" interface, it doesn't have setCustomFieldValue methoid.
You need "MutableIssue" interface you want to update this issue.
2) From API
https://docs.atlassian.com/software/jira/docs/api/8.1.0/com/atlassian/jira/issue/MutableIssue.html
setCustomFieldValue
void setCustomFieldValue(CustomField customField, Object value)
Sets a custom field value on this Issue Object, but does not write it to the database. This is highly misleading. To actually set a custom field value, use OrderableField.updateIssue(com.atlassian.jira.issue.fields.layout.field.FieldLayoutItem, MutableIssue, java.util.Map)
So you need "updateIssue" method from IssueManager
def CF = customFieldManager.getCustomFieldObject(<fieldID>);
MutableIssue issueToUpdate = (MutableIssue) event.issue;
issueToUpdate.setCustomFieldValue(CF, <newValue>);
issueManager.updateIssue(event.getUser(), issueToUpdate, EventDispatchOption.ISSUE_UPDATED, false);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.