User Tools

Site Tools


script_fields

This is an old revision of the document!


Scripted Fields

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

import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.component.ComponentAccessor;
 
IssueManager issueManager = ComponentAccessor.getIssueManager();
Set<String> tickets = issueManager.getAllIssueKeys(issue.id)
tickets = tickets.minus(issue.key)
if (tickets.isEmpty()) {
   return "N/A"
}
return tickets.join(', ')

Set Summary

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("CD-4","Insert your Summary");

Update custom field

def tgtField = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Name of custom field"}
def changeHolder = new DefaultIssueChangeHolder();
tgtField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(tgtField), "some new value"),changeHolder);
script_fields.1500317718.txt.gz · Last modified: 2017/07/17 14:55 by pawel