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

Priority change manualy

 

Hello,

I am looking for a option whenever the priorities field changed manually from Incident, Project "SMXBID"the Comment to be added automatically ""Priorities changed from Minor to Major" in Jira

I attached screendump , kindly see if i am using correct EVENT and also see below script where i get error message and no comment is added while executing.

Please assist my script , remeber it should add comment Old value to new value (""Priorities changed from Minor(old value) to Major"(new value) )

script.PNG

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.priority.Priority
issue.projectObject.key == 'SMXBID'
issue.issueType.name == 'Incident'
// Check if priority changeddef customFieldManager = ComponentAccessor.getCustomFieldManager()
def change = event?.getChangeLog()?.getRelated("ChildChangeItem").find

{it.field == "priority"}

if (change) {
log.warn "Priority Changed" 
}else{
log.warn "Priority remain same" 
}

 

1 answer

Hi Sharadkumar,

Priority field is a Jira system field and therefore, CustomFieldUpdatedEvent is not available for this case.

You should get the Priority's old value and new value then set the comment:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.priority.Priority
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.event.type.EventType

def issue = event.issue

def issueType = issue.issueType.name
//log.warn issueType

def commentManager = ComponentAccessor.getCommentManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

// Check if priority changed
def change = event?.getChangeLog()?.getRelated("ChildChangeItem").find{it.field == "priority"}


if(issueType == "Story"){ //If the issue type is "Story"
if (change) { //If the changed field is Priority field
def oldP = change.oldstring //Get the Priority's old value
def newP = event.issue.priority.name //Get the Priority's new value
log.warn "Priority Changed from $oldP to $newP."

//Add comment
commentManager.create(
issue,
user,
"Priority Changed from $oldP to $newP.",
false)

}else{
log.warn "Priority remain same"
}
}

You can select the Project(s) field with your project: "SMXBID" and Issue Updated event.

Hope this helps!

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Admins, notify your Jira instance of system-wide changes with the new admin announcement banner

Hi All! We’re excited to share the launch of an announcement banner that lets Jira site administrators communicate directly to their users across their  Jira Cloud instance.  ...

475 views 16 17
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