Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How do I modify a priority based on the value of a custom field for Jira Software Cloud

Charles Sterner
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 28, 2019

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");

 

 

1 answer

1 vote
Nir Haimov
Community Champion
January 28, 2019

Hi,

In Jira Cloud, everything you do with Scriptrunner is by JIRA REST API.

So simply follow the REST API:

https://developer.atlassian.com/cloud/jira/platform/rest/v3/?utm_source=%2Fcloud%2Fjira%2Fplatform%2Frest&utm_medium=302

And create a listener in Scriptrunner to perform a REST API call to update your field acording to your conditions.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events