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
4,363,959
Community Members
 
Community Events
168
Community Groups

Script to pdate the Prioirty automatically whenvere it changed

Hello,

 

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,

Sharad

1 answer

0 votes

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.

Ravi

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

Browse
Console
Built-in Scripts
Jobs
Listeners
Fields
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

@WithPlugin("com.atlassian.servicedesk")

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()
.author(user)
.body(text)
.issue(issueToComment)
.publicComment(!internal)
.build()

serviceDeskCommentService.createServiceDeskComment(user, createCommentParameters)
} else {
def commentParameters = CommentService.CommentParameters.builder()
.author(user)
.body(text)
.issue(issueToComment)
.build()

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

Hello,

 

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}"

}

 

script.PNG

Hello @Ravi Sagar _Sparxsys_ ,

 

I can see my listener script works perfectly fine whenever prioirity changes the comment to be updated in log.info 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.bc.issue.comment.property.CommentPropertyService
import com.atlassian.jira.issue.priority.Priority
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.issue.Issue
event.issue.issueType.name == '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}"}
//else
//
{log.warn "Priority remain same"}

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events