Hi,
I found this script and I am trying to adapt it to my needs and add it as a post function to the create step in my workflow so that when an issue is logged, it looks at a field and then updates the priority accordingly.
Custom Field - Cyber Incident Categorisation with the following options:
Account Compromise - P1
Host Compromise - P2
Phishing - P3
Denial of Service - P4
Extortion (Ransomware) - P5
Insider Threat - P1
Data Loss & Compromise - P2
Script:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.PriorityManager
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
final customFieldName = "Cyber Incident Categorisation"
//Get custom field issue with this name
def customFieldManager = ComponentAccessor.customFieldManager
def customField = customFieldManager.getCustomFieldObjects(issue).findByName(customFieldName)
assert customField: "Could not find custom field with name $customFieldName"
def customFieldVal = issue.getCustomFieldValue(customField) as LazyLoadedOption
//Create priorities
def priorities = ComponentAccessor.getComponent(PriorityManager).priorities
def highestPriority = priorities.findByName("P1")
def highPriority = priorities.findByName("P2")
assert highestPriority && highPriority: "One ore more selected priorities doesn't exist"
--- I actually need this to go up until P5 so would the additional priorities need to be added on and defined as such as medium, lower, lowest?
//Assign priority depending on the custom field value
switch (customFieldVal?.value) {
case "Account Compromise":
issue.setPriorityId(highestPriority.id)
break
case "Host Compromise":
issue.setPriorityId(highPriority.id)
break
default:
log.debug "No need to change the priority"
break
}
Any help would be appreciated.
Thanks.
Hello @Drishti Maharaj ,
I just tried your script. It is working fine, I only had to add this line at the end to update the issue :
ComponentAccessor.getIssueManager().updateIssue(ComponentAccessor.getUserManager().getUserByKey('user_key'), issue, EventDispatchOption.DO_NOT_DISPATCH, false);
Of course you will need to map all the priorities in your switch but that does not seem to be the issue.
Let me know if that helped.
Hi @Antoine Berry , thank you for taking the time to reply, if I add the additional script from you, the following error occurs:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Antoine Berry , I managed to figure out what was wrong :)
Just needed this at the top:
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.event.type.EventDispatchOption
and it worked perfectly!
Thank you so much!
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.