Hi folks,
I'm looking to automatically set a priority based on a custom field value either at the time of the ticket creation, or when the custom field is modified. My priorities are:
Priority ID 1 = Highest'
Priority ID 2 = High
Priority ID 3 = Medium
Priority ID 4 = Low
Unfortunately, I'm aware that you cannot set priority schemas on Jira Cloud. Since I have another project that uses these priorities, I cannot modify their names/values, so I created a custom field called Severity (custom , with the values:
Severity - 1
Severity - 2
Severity - 3
Severity - 4
From reading Script Runner documentation, I see that it should be possible to do this with a Groovy script, like this thread covers: https://community.atlassian.com/t5/Answers-Developer-Questions/Set-Priority-based-on-custom-field-post-function/qaq-p/476165
This is for Jira Sever however. I understand there are significant differences in ScriptRunner between Cloud and Server. I'm a complete beginner with Jira Cloud :/
Any idea on how to do this for Jira Cloud? My entire script (Jira Server) looks like:
import org.ofbiz.core.entity.GenericValue
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.event.type.EventDispatchOption;
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import org.apache.log4j.Category
log.info("[UpdateParentPriority] Script fired");
MutableIssue mutableIssue = (MutableIssue) issue;
ComponentManager componentManager = ComponentManager.getInstance();
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager();
CustomField customField = customFieldManager.getCustomFieldObject("customfield_10100"); // 10100 = Incident Severity CF
def customFieldValue = issue.getCustomFieldValue(customField);
switch (customFieldValue) {
case "Severity - 1":
mutableIssue.setPriorityId("1"); // 1 = Highest
log.info("[UpdateParentPriority] Priority 1 set to Highest");
break;
case "Severity - 2":
mutableIssue.setPriorityId("2"); // 2 = High
log.info("[UpdateParentPriority] Priority 2 set to High");
break;
case "Severity - 3":
mutableIssue.setPriorityId("3"); // 3 = Medium
log.info("[UpdateParentPriority] Priority 3 set to Medium");
break;
case "Severity - 4":
mutableIssue.setPriorityId("4"); // 4 = Low
log.info("[UpdateParentPriority] Priority 4 set to Low");
break;
default:
log.info("[UpdateParentPriority] ERROR - unable to set issue priority");
break;
}
// Update Issue
ComponentAccessor.getIssueManager().updateIssue(ComponentAccessor.getUserUtil().getUserObject('automation'), mutableIssue, EventDispatchOption.DO_NOT_DISPATCH, false);
log.info("[UpdateParentPriority] Script finished");
Hi,
In Jira Cloud, everything you do with Scriptrunner is by JIRA REST API.
So simply follow the REST API:
And create a listener in Scriptrunner to perform a REST API call to update your field acording to your conditions.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.