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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Script to pdate the Prioirty automatically whenvere it changed



I  am looking for Script runner with detailed step which fulfils my requirements

My requirement is whenever we change the priority in jira it displays normally Priority changed from Major to Minor but it does not display the same message in service portal which customer refer. Customer is always blind in service portal when the priority is changed

Hence i am looking or a script runner whenever we change the priority from Major to minor in Jira the comment to be automatically added in Service portal which is visible to customer "The priority for this issue has changed from Major to Minor"

I am aware it works with "Automation for Jira - Server" but i dont have this application and looking for only script runner

Thanks and Regards,


1 answer

0 votes
Ravi Sagar _Sparxsys_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Nov 16, 2020

Hi @Sharadkumar Bangera 

You can create a listener to check when the priority is changed and then add a comment.

Take a look at this post and this one for similar examples.

Give it a try and post your code here if you need further help.


Hi Ravi,


Thanks for the reply.

I am not expert in Script runner, i created few minor script in Behavior field but those are super easy. Can you please help me to correct below script

I m not sure in the below script where do i define

1) Project should be applicable to only  "TGE" project

2) Comment to be added in Jira whenever someone  change the priority to Critical to Major or Major to Minor and it should display in text ""Priority is changed from Critical to Major" and vice versa

3) Please confirm where do i write the script

Built-in Scripts
JQL Functions
REST Endpoints
Script Editor


import com.atlassian.jira.bc.issue.comment.CommentService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.servicedesk.api.comment.ServiceDeskCommentService
import com.onresolve.scriptrunner.runner.customisers.WithPlugin


final String Priority = "Blocker" // the key of the issue
final String comment = "Prioirity is changed to Blocker" // the comment you want to add

static void createServiceDeskComment(MutableIssue issueToComment, String text, Boolean internal) {
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser

if (issueToComment.projectObject.projectTypeKey.key == "service_desk") {
def serviceDeskCommentService = ComponentAccessor.getOSGiComponentInstanceOfType(ServiceDeskCommentService)

def createCommentParameters = serviceDeskCommentService.newCreateBuilder()

serviceDeskCommentService.createServiceDeskComment(user, createCommentParameters)
} else {
def commentParameters = CommentService.CommentParameters.builder()

def commentService = ComponentAccessor.getComponent(CommentService)
def validationResult = commentService.validateCommentCreate(user, commentParameters)
commentService.create(user, validationResult, true)

//Example of function in use
def issueManager = ComponentAccessor.issueManager
def issue = issueManager.getIssueByCurrentKey(issueKey)

createServiceDeskComment(issue, comment, true) //false means public, true means internal



I am working on  Listener custom Script for my query whenever the Priorities change the Comment to be added in Jira "Priorities changed from Major to Minor".I am not good in scripting.

I m using below script but  it require a correction. Please help me where do i define the priority and comment "Priorities changed from Major to Minor".


import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.model.ChangeGroup
import com.atlassian.jira.model.ChangeItem
import com.atlassian.jira.issue.history.ChangeItemBean

def commentManager = ComponentAccessor.getCommentManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()

def issue = event.issue
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def cf = customFieldManager.getCustomFieldObjectByName("SomeDate")
def sd= cf.getValue(issue) as Date
def someDate = sd.format("yyyy-MM-dd")

String comment = "*Automatic comment:* SomeDate was updated to " + someDate

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "Single User Picker CF"}

if (change) {
log.debug "Value changed from ${change.oldstring} to ${change.newstring}"




Hello @Ravi Sagar _Sparxsys_ ,


I can see my listener script works perfectly fine whenever prioirity changes the comment to be updated in but i m looking for  whenever priority changes the comment to be added in Jira.

Can you please correct my below script to addcomment

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.priority.Priority
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.issue.Issue == 'Incident'

def CustomFieldManager = ComponentAccessor.getCustomFieldManager()
def commentManager = ComponentAccessor.getCommentManager()
def change = event?.getChangeLog()?.getRelated("ChildChangeItem").find
def comment = event.comment?.body
{it.field == "priority"}

if (change)

{commentManager.create("Value changed from ${change.oldstring} to ${change.newstring}")}
{log.warn "Priority Changed"}

//{log.warn "Value changed from ${change.oldstring} to ${change.newstring}"}
{log.warn "Priority remain same"}

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events