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

Script listener to add comment

Hello,

 

i m trying to add comment in Jira  whenever priorities changes but endup with error.

Please help me to correct my script

 

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

 

1 answer

1 accepted

1 vote
Answer accepted
Hana Kučerová Community Leader Nov 25, 2020

Hi @Sharadkumar Bangera ,

please try something like this:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.comments.CommentManager
import static com.atlassian.jira.issue.IssueFieldConstants.PRIORITY

CommentManager commentManager = ComponentAccessor.getCommentManager()
def change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == PRIORITY}
if (change) {
commentManager.create(event.issue, event.user, "Value changed from ${change.oldstring} to ${change.newstring}", false)
}

Hi Hana,

 

Thanks a ton.

My script is working as expected..I was struggling for from last few days to get the desired result and you appeard as angel with the miracle script.

 

Thanks a lot.

Like Hana Kučerová likes this
Hana Kučerová Community Leader Nov 26, 2020

Thanks, you are very kind, I'm glad to help :-)

Hi @Hana Kučerová ,

 

Sorry to bother you one more time.

The script is working as expected but it shows my name whenever the priority is changed

Sharadkumar Kariya Bangera 27/Nov/20
Priority changed from Minor to Trivial

I am looking this should show Service Desk Automation user

Priority changed from Minor to Trivial 27/Nov/20

Hana Kučerová Community Leader Nov 27, 2020

Hi @Sharadkumar Bangera ,

please try to modify it like this:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.user.ApplicationUser
import static com.atlassian.jira.issue.IssueFieldConstants.PRIORITY

CommentManager commentManager = ComponentAccessor.getCommentManager()
ApplicationUser user = ComponentAccessor.getUserManager().getUserByKey("username")
def change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == PRIORITY}
if (change) {
commentManager.create(event.issue, user, "Value changed from ${change.oldstring} to ${change.newstring}", false)
}

Just replace "username" with the username of your automation user.

This automation user needs to have set of permissions for your project like Browse Projects and Add Comments.

Thanks @Hana Kučerová for your help.

I tried your script but it still reflects my name instead of "ServicedeskAutomation".

i change the username to "ServicedeskAutomation"(this is how it is created in User Management)

ServicedeskAutomation have Administer Permission to projects

 

What i m looking is

Service Desk Automation

Priority changed from Minor to Major

 

At Present it appear as

Sharadkumar Kariya Bangera 27/Nov/20
Priority changed from Minor to Trivial

sorry , My bad.i over-read your script , made changes on last line ".It is working as expected but the comment appears as "internal" and i want this to be public

commentManager.create(event.issue, user, 

"instead of

commentManager.create(event.issue, event.user, 
Hana Kučerová Community Leader Nov 27, 2020

Hi @Sharadkumar Bangera ,

I believe your automation user needs to have Service Desk license, to be able to communicate with your customers. Would you please check?

Hi Hana,

 

Thanks for your assistance.

I will check as per your comment.

 

Thanks once again.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

461 views 5 18
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