Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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

Listener to update "Priority Degree" single list custom field and the priority of all linked issues

Hi,

I need the listener check if priority or "priority degree is changed, if yes it will update all the linked isssues.

Q-What should be the value of Events I should set in the listener configurations?

I can update the single list custom field "priority degree" in all linked issues but it give error when I try to update the priority, I get error that It can not find matched method for the following two lines:

currentIssue.setPriorityId(ComponentAccessor.getConstantsManager().getPriorities().find{it.getName().equals(newValue)}.getId());
ComponentAccessor.getIssueManager().updateIssue(currentUser, linkedIssues[i], EventDispatchOption.ISSUE_UPDATED, false)

 

Here is the whole code of the listener:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

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

IssueManager issueManager = ComponentAccessor.getIssueManager();
def mutableIssue = issueManager.getIssueObject(event.issue.id)
// Check if Developer changed
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def change = event?.getChangeLog()?.getRelated("ChildChangeItem").find {it.field == "priority"}

def prioritychange = event?.getChangeLog()?.getRelated("ChildChangeItem").find

{it.field == "priority"}
MutableIssue issue = event.issue as MutableIssue

def originalIssue = ComponentAccessor.getIssueManager().getIssueByCurrentKey(issue.getKey())

def customFieldName = "Priority Degree"
def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName(customFieldName).first()

def customField = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue)?.find { it.name == customFieldName }

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

def linkedIssues = ComponentAccessor.getIssueLinkManager().getLinkCollection(issue, currentUser).getAllIssues()

log.info ("newwwww degreee : " + issue.getCustomFieldValue(cf).toString() +" Olddddd degree : " + originalIssue.getCustomFieldValue(cf).toString() )
log.info(" Originallll priority value "+ originalIssue.getPriority() +" "+" Newwwww priority value "+ issue.getPriority());

 

if (change) {

if (linkedIssues.size() > 0){
log.warn (" Helooooo777777777777777777 I found the following linked number of issues : " + linkedIssues.size() )

for (int i = 0; i < linkedIssues.size(); i++){

//def linkedIssue = linkedIssues[i].destinationObject
def oldValue = linkedIssues[i].getCustomFieldValue(customField)
def newValue = issue.getCustomFieldValue(cf).toString()

def optionsManager = ComponentAccessor.getOptionsManager()
def config = customField.getRelevantConfig(issue)
def options = optionsManager.getOptions(config)
def optionToSelect = options.find { it.value == newValue }

//update the single list custom field
customField.updateValue(null, linkedIssues[i], new ModifiedValue(issue.getCustomFieldValue(customField), optionToSelect), new DefaultIssueChangeHolder())

//Update the custom priority
def oldPriorityValue = linkedIssues[i].priority
def newPriorityValue = issue.getPriority()

currentIssue.setPriorityId(ComponentAccessor.getConstantsManager().getPriorities().find{it.getName().equals(newValue)}.getId());
ComponentAccessor.getIssueManager().updateIssue(currentUser, linkedIssues[i], EventDispatchOption.ISSUE_UPDATED, false)

}

}

}


Thanks

1 answer

Hi Mohamed,

what is the variable "currentIssue" stands for, it seems like you didn't defined it...

Dar

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

5 mobile apps for Jira Cloud to boost productivity

  It’s very important to have access to the workflow process from anywhere. Especially if you manage the work of others. There is no difference whether you’re out of office, or drive a ca...

249 views 2 5
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