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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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}"
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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"}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.