This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
script_fields [2017/05/30 11:32] pawel created |
script_fields [2019/07/11 09:28] (current) root |
||
---|---|---|---|
Line 3: | Line 3: | ||
ScriptRunner allows you to script specific ScriptRunner fields. As an example, if you move an issue to a different project, a new key is assigned. Jira is smart enough that it keeps the old key as well, so if you search for the old issue key, you will be redirected to the new issue key. If for some reason you'd like to find out what the previous key is, you can script this with a ScriptRunner field. Following code can be used in for the Script Field: | ScriptRunner allows you to script specific ScriptRunner fields. As an example, if you move an issue to a different project, a new key is assigned. Jira is smart enough that it keeps the old key as well, so if you search for the old issue key, you will be redirected to the new issue key. If for some reason you'd like to find out what the previous key is, you can script this with a ScriptRunner field. Following code can be used in for the Script Field: | ||
+ | ==== Get Old Key ==== | ||
<code java> | <code java> | ||
Line 16: | Line 17: | ||
return tickets.join(', | return tickets.join(', | ||
</ | </ | ||
+ | |||
+ | ==== Set Summary ==== | ||
+ | |||
+ | <code java> | ||
+ | import com.atlassian.jira.issue.Issue; | ||
+ | import com.atlassian.jira.issue.IssueManager; | ||
+ | import com.atlassian.jira.issue.MutableIssue; | ||
+ | import com.atlassian.jira.component.ComponentAccessor; | ||
+ | |||
+ | void setSummary(String key,String newSummary) { | ||
+ | IssueManager im = ComponentAccessor.getIssueManager(); | ||
+ | MutableIssue issue = im.getIssueObject(key); | ||
+ | issue.setSummary(newSummary); | ||
+ | issue.store(); | ||
+ | } | ||
+ | |||
+ | setSummary(" | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== Drop Down Values based on Transitions ==== | ||
+ | Create this as an initialiser. | ||
+ | <code java> | ||
+ | import com.atlassian.jira.component.ComponentAccessor | ||
+ | import static com.atlassian.jira.issue.IssueFieldConstants.* | ||
+ | |||
+ | def customFieldManager = ComponentAccessor.getCustomFieldManager() | ||
+ | def optionsManager = ComponentAccessor.getOptionsManager() | ||
+ | |||
+ | def formField = getFieldByName(" | ||
+ | def customField = customFieldManager.getCustomFieldObject(formField.getFieldId()) | ||
+ | def config = customField.getRelevantConfig(getIssueContext()) | ||
+ | def options = optionsManager.getOptions(config) | ||
+ | |||
+ | // Set the values inside the select list field | ||
+ | def noneMap = [" | ||
+ | |||
+ | |||
+ | if (getActionName() == "Need More Info") { | ||
+ | def optionsMap = noneMap + options.findAll { | ||
+ | it.value in [" | ||
+ | }.collectEntries { | ||
+ | [ | ||
+ | (it.optionId.toString()) : it.value | ||
+ | ] | ||
+ | } | ||
+ | formField.setFieldOptions(optionsMap) | ||
+ | } else if (getActionName() == " | ||
+ | def optionsMap = noneMap + options.findAll { | ||
+ | it.value in [" | ||
+ | }.collectEntries { | ||
+ | [ | ||
+ | (it.optionId.toString()) : it.value | ||
+ | ] | ||
+ | } | ||
+ | formField.setFieldOptions(optionsMap) | ||
+ | } else if (getActionName() == " | ||
+ | def optionsMap = noneMap + options.findAll { | ||
+ | it.value in [" | ||
+ | }.collectEntries { | ||
+ | [ | ||
+ | (it.optionId.toString()) : it.value | ||
+ | ] | ||
+ | } | ||
+ | formField.setFieldOptions(optionsMap) | ||
+ | } else { | ||
+ | def optionsMap = noneMap + options.findAll { | ||
+ | it.value in [" | ||
+ | }.collectEntries { | ||
+ | [ | ||
+ | (it.optionId.toString()) : it.value | ||
+ | ] | ||
+ | } | ||
+ | formField.setFieldOptions(optionsMap) | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | References: | ||
+ | [[https:// | ||
+ | [[https:// | ||
+ | |||
+ |