I am trying to write a listener that will update the "priority" field of all sub-tasks when the parent is updated.
I currently have a listener that works on custom fields...However, since "priority" is not a custom field, my script returns a nullValue error when I try to access the priority field using the method getCustomFieldValue()
Further, the methods getFieldById() - getFieldByName() only work in behaviours.
The ScriptRunner docs do not provide any valuable information for this specific case...
Regarding listeners:
WHAT METHOD CAN I USE TO ACCESS THE PRIORITY FIELD??
WHAT METHOD CAN I USE TO UPDATE THAT FIELD IN A SUB-TASK?
The Java API documentation for your version of Jira is your best friend.
When you look up the issue object, you will see that issue.getPriority() will return a Priority object
def priority = issue.getPriority()
issue.subTaskObjects.each{subTask ->
subTask.setPriority(priority)
issueManager.updateIssue(currentUser, subTask, EventDispatchOption.DO_NOT_DISPATCH, false)
//don't forget to re-index the subtask
}
Thank you for the fast response! Here is my script thus far
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import java.lang.Object
import com.atlassian.jira.ofbiz.AbstractOfBizValueWrapper
import com.atlassian.jira.issue.IssueConstantImpl
import com.atlassian.jira.issue.priority.PriorityImpl
import com.atlassian.jira.issue.priority
Issue issue = event.issue
def priority = issue.getPriority()
def issueManager = ComponentAccessor.getIssueManager();
issue.subTaskObjects.each{subTask ->
subTask.setPriority(priority)
issueManager.updateIssue(currentUser, subTask, EventDispatchOption.DO_NOT_DISPATCH, false)
issueIndexManager.reIndex(subTask)
}
I get the error: unable to resolve class com.atlassian.jira.issue.priority (this import is taken from the docs you provided)
Without that import, the error is thrown on the method setPriority(), as it cannot recognize it without the import...
What am I missing?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here is a full script that works for me in my environment:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.event.type.EventDispatchOption
def issue= event.issue
def issueManager = ComponentAccessor.getIssueManager();
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def indexingService = ComponentAccessor.getComponent(IssueIndexingService.class)
def priority = issue.getPriority()
issue.subTaskObjects.each{subTask ->
subTask.setPriority(priority)
issueManager.updateIssue(currentUser, subTask, EventDispatchOption.DO_NOT_DISPATCH, false)
boolean wasIndexing = ImportUtils.isIndexIssues()
ImportUtils.setIndexIssues(true)
indexingService.reIndex(subTask)
ImportUtils.setIndexIssues(wasIndexing)
}
I do get static type checking errors. But they don't impact the ability to run.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you again for the prompt response!
You were correct about the static type checking errors. They led me to believe I was missing an import.
My console shows two such errors but they do not impact that ability to run the script successfully.
I may throw a log in my script to note the errors. Other than that, everything works.
May riches and good fortune bless you for the remainder of your days!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@PD Sheehan
How do i add the priority in the comment ?
i have defined
def priority = issue.getPriority()
and in comment
(priority)
i get an error
---------------------------------------------------------------------
IssueConstantImpl[[GenericEntity:Priority][sequence,3]statusColor,#707070[name,3][iconurl,/images/icons/priorities/low.svg][description,Normal regression testing effort.][id,3]]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you have a priority object retrieved from issue.getPriority() and you want to display it a new comment body string, you probably want to grab the name of the priority.
def priority = issue.getPriority()
def bodyString = "Some comment with prioirity name: ${priority.name}"
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.