Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Scriptrunner custom listner update status Edited

Dears,

 

I am trying to update the priority of an issue based on impact and urgency. I have all bits of code, but the last step (updating the priority is not working. It also does not trigger an error.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.priority.Priority
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.event.type.EventDispatchOption;

log.error(event.issue.priority)
log.error(event.issue.priority?.name)


MutableIssue currentIssue = event.issue as MutableIssue
Issue issue = event.getIssue();
def impact = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Impact")
log.error(event.getIssue().getCustomFieldValue(impact))
def urgency = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Urgency")
log.error(event.getIssue().getCustomFieldValue(urgency))
String priority="Low";
log.error(event.issue.priority)
for(Priority priority1: ComponentAccessor.getConstantsManager().getPriorities()){
    log.error(priority1.getName() + " " +priority )
    if(priority1.getName().equals(priority)){
        log.error("Woehoe" )
        currentIssue.setPriorityObject(priority1)
        currentIssue.setPriorityId(priority1?.id)
        
    }
}
log.error(event.issue.priority)
ComponentAccessor.getIssueManager().updateIssue(null, currentIssue, EventDispatchOption.ISSUE_UPDATED, false);

log.error(event.issue.priority)



in meantime I have done additional tests. Apparently if my script ran, the issue priority is set. But in the background something is setting back the priority to it's previous sate.

 

 

 

 

 

 

 

 

 

1 answer

1 accepted

0 votes
Answer accepted

The issue is solved and I guess it is related to the following fact. The trigger is executed prior to the actual update. The changes I am doing in the code above is on the issue and not on the updateIssue. Therefore it get's overridden. Following code does the trick:

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.Issue

import com.atlassian.jira.issue.IssueInputParametersImpl

import com.atlassian.jira.issue.customfields.option.Option

import com.atlassian.jira.issue.priority.Priority

import com.atlassian.jira.issue.Issue

import com.atlassian.jira.event.type.EventDispatchOption;

 

//set default values

String impactDefault = "Medium"

String UrgencyDefault = "Medium"

 

//create variables

def issue = event.issue as Issue

def impact = impactDefault

def urgency = UrgencyDefault

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

 

//get helpers

def customFieldManager = ComponentAccessor.getCustomFieldManager()

def constantsManager = ComponentAccessor.getConstantsManager()

def issueService = ComponentAccessor.getIssueService()

 

//get the custom fields for the priority check

try{

    def urgencyField = customFieldManager.getCustomFieldObjectByName("Urgency")

    urgency = issue.getCustomFieldValue(urgencyField) as String

    if(urgency==null){urgency=UrgencyDefault}

}catch(Exception ex){}

try{

    def impactField = customFieldManager.getCustomFieldObjectByName("Impact")

    impact = issue.getCustomFieldValue(impactField) as String

    if(impact==null){impact = impactDefault}

}catch(Exception ex){}

 

//define the priority

String priority ="";

 

log.error("U:" + urgency + " I:" + impact)

switch(urgency.trim()){

    case "High":

       log.error("Switch: " + urgency)

       switch(impact.trim()){

            case "High":

            log.error("Switch: " + impact)

            priority = "Highest"

            break;

            case "Medium":

            log.error("Switch: " + impact)

            priority = "High"

            break;

            case "Low":

                    log.error("Switch: " + impact)

            priority = "Medium"

            break;

       }

    break;

    case "Medium":

             switch(impact.trim()){

            case "High":

                priority = "High"

            break;

            case "Medium":

                priority = "Medium"

            break;

            case "Low":

                priority = "Low"

            break;

       }

    break;

    case "Low":

       switch(impact.trim()){

            case "High":

            priority = "Medium"

            break;

            case "Medium":

            priority = "Low"

            break;

            case "Low":

            priority = "Lowest"

            break;

       }

    break;

}

log.debug(priority)

 

//create an object for the input parameters

def issueInputParameters = new IssueInputParametersImpl()

 

//get the priorities

for(Priority priority1: ComponentAccessor.getConstantsManager().getPriorities()){

    log.error(priority1.getName() + " " +priority )

    if(priority1.getName().equals(priority)){

        issueInputParameters.setPriorityId(priority1?.id)       

    }

}

 

issueInputParameters.setSkipScreenCheck(true)

 

//validate the update

def validationResult = issueService.validateUpdate(user, issue.id, issueInputParameters)

 

 

//execute the updat

if (validationResult.isValid()) {

    issueService.update(user, validationResult)

} else {

    log.error validationResult.errorCollection.errors

}

Kind regards,

Matt

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase

The benefits of using Jira in different departments

Jira is a great tool to use across different departments. Forget that paperwork – switch to Jira and get that tasks done smoothly. Marketing Jira allows for a complete digital transformation of you...

101 views 0 6
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you