EDIT: Thanks toAlexey Matveev the script is now working and all questions are solved
Below the edited script which works for JIRA 7.4.x Server
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.priority.Priority
import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.atlassian.jira.event.type.EventDispatchOption
def currentIssue = (MutableIssue) issue
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
//switch depending on the values of custom field and set priority accordingly
switch (customFieldManager.getCustomFieldObjectByName("Name of custom field").getValue(currentIssue).toString())
{
case "1. First value custom field":
currentIssue.setPriorityId(ComponentAccessor.getConstantsManager().getPriorities().find{it.getName().equals("Here goes the first priority name")}.getId());
break;
case "2. Second value custom field":
currentIssue.setPriorityId(ComponentAccessor.getConstantsManager().getPriorities().find{it.getName().equals("Here goes another priority name")}.getId());
break;
case "3. Third value custom field":
currentIssue.setPriorityId(ComponentAccessor.getConstantsManager().getPriorities().find{it.getName().equals("Here goes the last priority name")}.getId());
break;
default:
break;
}
// Update Issue
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)
Hello,
1. You can find IDs of priorities if you go to cog item->issues->priorities and then hover on the edit item.
2. If you want to save the issue then add your post-function first in the list of post functions or add to the script in the first line
import com.atlassian.jira.event.type.EventDispatchOption
and add to the end of your script
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)
You updated the script. So what are now your questions? Are they the same?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Alexey,
thanks for your answer - problem 2 saving the issue is solved!!!
However, I was still not able to find the ID of priority.
We use JIRA Server 7.4.x
1. I go to issues --> Issue attributes -->Priorities
2. The list of the priorities is displayed
Problem:
When I hover over the link "Edit" in the column Actions there is no priority displayed
When I choose edit I can neither see nor change priority
Am I missing the meaning of " cog item"?
Thanks,
Sven
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Do it another way
change
currentIssue.setPriorityId('3');
to
currentIssue.setPriorityId(ComponentAccessor.getConstantsManager().getPriorities().find{it.getName().equals("High")}.getId()))
Instead "High" you put your required priority
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.