I am writing a custom script on the event "Issue Moved" to change the priority to "Critical".
Basically I want that whenever an "Incident" is moved to issue type "HotFIx" ; the priority gets changed to "Critical".
My code is as below. But doesn't seem to be working. There are syntax errors for eg:
No Such Property : issueTypeObject for class : java.lang.Class
Can you suggest?
import com.atlassian.jira.issue.Issue
if(Issue.issueTypeObject.name == "HotFix")
{Issue.setPriority() = "Critical"}
Does not seem to be working for me. When I am trying to convert issue type from Incident with Major Priority to Hotfix issue type the priority remains as Major and does not change to Critical.
But I also noticed that below the script there is a small text that says "Has not Run Yet".
Is there something I am missing.
It looks like the script didn't get triggered for "Issue Moved" event. I changed the event to "Issue Updated" and modified the code as follows and it works:
import com.atlassian.jira.issue.MutableIssue; import com.atlassian.jira.event.type.EventDispatchOption; import com.atlassian.jira.component.ComponentAccessor; // Retrieve necessary objects def jac = ComponentAccessor.getJiraAuthenticationContext(); def im = ComponentAccessor.getIssueManager(); def chm = ComponentAccessor.getChangeHistoryManager(); // Retrieve the updated issue MutableIssue currentIssue = (MutableIssue)event.getIssue(); // Get the most recent changes def allChangeItems = chm.getChangeHistories(currentIssue); def allRecentChanges = allChangeItems[allChangeItems.size() - 1].getChangeItemBeans(); // Go through the recently changed items and check if issuetype is one of them for (int i = 0; i < allRecentChanges.size(); i++) { if (allRecentChanges[i].getField() == "issuetype") { // Check if the new issue type is HotFix if (allRecentChanges[i].getToString() == "HotFix") { // Set priority value currentIssue.setPriorityId("2"); // Save issue im.updateIssue(jac.getLoggedInUser(), currentIssue, EventDispatchOption.ISSUE_UPDATED, false); } else { continue; } } else { continue; } }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The actual code would be:
import com.atlassian.jira.issue.MutableIssue; import com.atlassian.jira.event.type.EventDispatchOption; import com.atlassian.jira.component.ComponentAccessor; // Retrieve necessary objects def jac = ComponentAccessor.getJiraAuthenticationContext(); def im = ComponentAccessor.getIssueManager(); // Retrieve the updated issue MutableIssue currentIssue = (MutableIssue)event.getIssue(); if (currentIssue.getIssueTypeObject().getName() == "HotFix") { // Set priority value currentIssue.setPriorityId("2"); // Save issue im.updateIssue(jac.getLoggedInUser(), currentIssue, EventDispatchOption.ISSUE_UPDATED, false); }
In our JIRA instance, the priority ID for "Critical" is "2". Hope that helps!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.