Hi!
I need to create linked issue of type B based on source issue of type A (both of them in the same project).
I decide to do this using ScriptRunner "Constrained create issue dialog" and "Behaviors" and not by workflow transition and post-script function cause I need to give end user the ability to change some values before linked issue's creation.
Some issue fields in both types are the same and should be pre-filled before using initialiser.
But now I stuck at label-type custom field. There is two the same label CF in type A issue and type B issue.
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.label.Label
import com.atlassian.jira.issue.label.LabelManager
import java.sql.Timestamp
IssueManager issueManager = ComponentManager.getComponentInstanceOfType(IssueManager)
Issue originalIssue = issueManager.getIssueObject(getContextIssueId())
CustomFieldManager customFieldManager = ComponentManager.getComponentInstanceOfType(CustomFieldManager)
OptionsManager optionsManager = ComponentManager.getComponentInstanceOfType(OptionsManager)
LabelManager labelManager = ComponentManager.getComponentInstanceOfType(LabelManager)
if (getBehaviourContextId() == "bankiru-create-media-issue") {
CustomField customField
def config
def options
Set<Label> z = []
// Summary
getFieldById("summary").setFormValue(originalIssue.getSummary())
getFieldById("summary").setReadOnly(true)
// IssueType
getFieldById("issuetype-field").setReadOnly(true)
// Project
getFieldById("project-field").setReadOnly(true)
List<CustomField> originalCustomFields = customFieldManager.getCustomFieldObjects(originalIssue)
originalCustomFields.each { cf ->
def parentValue = cf.getValue(originalIssue)
if (!parentValue || !getFieldById(cf.id)) return
if (parentValue instanceof String) {
getFieldById(cf.id).setFormValue(parentValue)
return
}
/*
some code here...
*/
if (cf.customFieldType.name == "Labels") {
parentValue.each {
getFieldById(cf.id).setFormValue(it.label)
}
getFieldById(cf.id).setFormValue(z)
}
}
getFieldById("issuelinks-linktype").setFormValue("blocks").setReadOnly(true)
getFieldById("issuelinks-issues").setFormValue(originalIssue.key).setReadOnly(true)
}
No errors, no warnings... Just don't work. There's no porblems with other field types, only with this label field.
Any suggestions?
Jira 7.4.1, ScriptRunner 5.5.9