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

Use generic service desk account to answer customers

Edited

I would to answer with an generic account in my service Desk. But I want to know who make the answer in internal.

I use the script Listeners and the event : ServiceDeskCommentEvent

The script must to do :

Verify if account is service Desk
Verify if answer is for customer (external)
Delete the last comment
Write internal comment with the current user
Write external comment with generic account of service Desk

I do all of that if I know the Issue number. (with getIssueByCurrentKey() )

Now I would to do this with all issues when the event is trigerring. But it's not working with issueEvent.getIssue().

I need this kind of function for all events on Issues comments
Thanks

import com.atlassian.crowd.embedded.api.Group
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.comments.MutableComment
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.util.json.JSONObject
import com.atlassian.jira.bc.issue.comment.property.CommentPropertyService
import com.atlassian.jira.issue.comments.Comment
import groovy.json.JsonSlurper

final SD_PUBLIC_COMMENT = "sd.public.comment"

CommentManager commentManager = ComponentAccessor.getCommentManager()

//def issue = issueEvent.getIssue()

//def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("I-01")

def groupManager = ComponentAccessor.getGroupManager()

ApplicationUser supportUser = ComponentAccessor.getUserManager().getUserByName("ahl")
ApplicationUser currentUser = commentManager.getLastComment(issue).authorApplicationUser

MutableComment mutableCommentSupport = (MutableComment) commentManager.getLastComment(issue)

def comment = commentManager.getLastComment(issue)

def commentPropertyService = ComponentAccessor.getComponent(CommentPropertyService)

def isInternal = { Comment c ->
def commentProperty = commentPropertyService.getProperty(currentUser, c.id, SD_PUBLIC_COMMENT).getEntityProperty().getOrNull()
if (commentProperty) {
def props = new JsonSlurper().parseText(commentProperty.getValue())
props['internal']
}
else {
null
}
}

if (comment) {
if(isInternal(comment) == false) {
//Properties
def properties = [(SD_PUBLIC_COMMENT): new JSONObject(["internal": true] as Map)]

if (['Hotline','jira-servicedesk-users'].any {groupManager.isUserInGroup(currentUser, it)}){
if(currentUser != supportUser) {

//delete original comment
commentManager.delete(commentManager.getLastComment(issue))

//External comment
commentManager.create(issue, supportUser, mutableCommentSupport.body, false)
//Internal comment
commentManager.create(issue, currentUser, mutableCommentSupport.body, null, null, new Date(), properties, false)
}
}
}
}

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Admins, notify your Jira instance of system-wide changes with the new admin announcement banner

Hi All! We’re excited to share the launch of an announcement banner that lets Jira site administrators communicate directly to their users across Jira Cloud instance.   📢 Get y...

163 views 7 8
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