I'm using custom mailhandler to add comment generated through mail body. Till now script that is mentioned below does great job of adding comment in existing ticket, but comments created by customers are marked as internal.
Is there any way to add comments created through mailhandler from all users(customers) also those who are non-agent users as external comments?
Well it worked, when I use createComment(issue, user, body, dispatchEvent) method and set dispatchEvent attribute to False, but I need event to be dispatched as there are project automations that need to be triggered when new comment is created which will be only triggered when dispatchEvent attribute is set to True.
After setting dispatchEvent attribute to true, again all comments created by some(non-agent) users are marked as internal which I don't want.
I also tried using serviceDeskCommentService and passed publicComment as True but still comments were marked as internal.
Below is the mailhandler code:
imports ...
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
def optionsManager = ComponentAccessor.optionsManager
def setOption
def senders = MailUtils.getSenders(message)
def projectManager = ComponentAccessor.getProjectManager()
def issueFactory = ComponentAccessor.getIssueFactory()
def messageUserProcessor = ComponentAccessor.getComponent(MessageUserProcessor)
CommentManager commentManager = ComponentAccessor.commentManager
def userUtil = ComponentAccessor.getUserUtil()
def userSearchService = ComponentAccessor.getComponent(UserSearchService)
def userManager = ComponentAccessor.getComponent(UserManager)
def subject = message.getSubject() as String
def body = MailUtils.getBody(message)
def issue = ServiceUtils.findIssueObjectInString(subject)
def issueObject = issueFactory.getIssue()
//getting attachments
def attachments = MailUtils.getAttachments(message)
if (issue) {
final addCommentAsPublic = true
def findUsersByEmail = userSearchService.findUsersByEmail(senders)
def user = findUsersByEmail.first()
//comments creation
//messageHandlerContext.createComment(issue, user, comment, true)
createComment(user as ApplicationUser, comment as String, issue as Issue, addCommentAsPublic as Boolean)
log.warn"=======================> comment added "
}
//if ticket doesn't exist in Jira
else{
//code to create new ticket
}
}
############################################
void createComment(ApplicationUser commentUser, String commentBody, Issue issue, Boolean publicComment) {
@PluginModule ServiceDeskCommentService serviceDeskCommentService
@PluginModule CustomerContextService customerContextService
customerContextService.runInCustomerContext {
def createCommentParameters = serviceDeskCommentService.newCreateBuilder()
.author(commentUser)
.body(commentBody)
.issue(issue)
.publicComment(publicComment)
.build()
serviceDeskCommentService.createServiceDeskComment(commentUser, createCommentParameters)
}
}
Is there any changes/method/way so that visibility of all the comments is set to external by default?
Thanks.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.