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"}
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks, you are very kind, I'm glad to help :-)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
Priority changed from Minor to Major
At Present it appear as
Sharadkumar Kariya Bangera 27/Nov/20
Priority changed from Minor to Trivial
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.
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,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Hana,
Thanks for your assistance.
I will check as per your comment.
Thanks once again.
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.