Forums

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

Alter priority

Deleted user August 9, 2021

good afternoon I'm creating a script so when an IM is opened it sets the priority according to the summary, where if the summary contains p2 it creates the Im with Medium priority, but it's only creating with low priority, follow the script

 

 

import groovy.json.JsonSlurper;import groovy.json.StreamingJsonBuilder;import com.atlassian.jira.component.ComponentAccessor;import com.atlassian.jira.project.Projectimport java.net.URLimport java.net.URLEncoderimport com.atlassian.jira.issue.label.LabelManager
// veifica se não tem label de OpsgenieLabelManager labelManager = ComponentAccessor.getComponent(LabelManager)def labels = labelManager.getLabels(issue.id).collect{it.getLabel()}def issuetype = issue.getIssueType().name;
def projeto = issue.getProjectObject().getKey()if(projeto == "SDTEST"){        def priorityP2     def priorityP1         if(issue.getSummary().contains("P2")) priorityP2 = "Medium"            if(issue.getSummary().contains("P1")) priorityP1 = "High"}

2 answers

0 votes
Daniel Ebers
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 13, 2021

Hi @[deleted]

in case the script is not a hard requirement you likely could do this using automation which comes without any additional cost in your plan.

The rule could look like this:

grafik.png

You can learn more about Automation in Jira here:

Regards,
Daniel

Deleted user August 13, 2021

Bom dia Daniel, tudo bem ? 

Eu fiz essa automação porem em alguns momentos ela falha não alterando a prioridade por isso pensei em fazer via script

import com.atlassian.jira.component.ComponentAccessor;import com.atlassian.jira.event.type.EventDispatchOption;import com.atlassian.jira.issue.UpdateIssueRequest;import com.atlassian.jira.config.PriorityManager
def issuetype = issue.getIssueType().name;def customFieldManager = ComponentAccessor.getCustomFieldManager()def issueManager = ComponentAccessor.getIssueManager()def userLogged = ComponentAccessor.getJiraAuthenticationContext().loggedInUser

def currentPriority = issue.getPriority().getId() //return the ID of the priority of the issuedef projeto = issue.getProjectObject().getKey()log.info("kEY - " + issue.key)log.info("Prioridade Atual- " + currentPriority)
switch(projeto == "SDTEST" && issuetype == "Incident"){
    case issue.getSummary().contains("P2"):   issue.setPriorityId("7"// 7 é o id da priority Medium    break    case issue.getSummary().contains("P1"):    issue.setPriorityId("10002"// 10002  é o id da priority High    break   } log.info("Nova Prioridade  - " + issue.getPriority().getId())
issueManager.updateIssue(userLogged, issue, EventDispatchOption.DO_NOT_DISPATCH, false); 


0 votes
Joseph Chung Yin
Community Champion
August 9, 2021

@[deleted] -

Please verify the following items -

1)Ensure that the priority scheme associated with your project has "Medium" as an option.  Is there a default option set against the priority scheme?  I am sure the default option is "Low".

2) Your code seems to be incomplete - It seems you only populated the local variable prorityP1 and priorityP2.  You still need to have calls setting the issue priority field (example - setPriorityId("") ) and update the issue.

Hope this helps.

Best, Joseph Chung Yin

Jira/JSM Functional Lead, Global Infrastructure Applications Team

Viasat Inc.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events