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,365,544
Community Members
 
Community Events
168
Community Groups

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

Atlassian Community Events