Show attachments in Jira Service Management comments

Originally asked by Sonal Otwani on 11 October 2022 (original question)


Hi,

I have connection from ServiceNow to Jira Service Management project. The attachments are synchronised from Snow to JSM. But I want to show these attachments in comments as well.

Does Exalate support this use case?

Thanks,


Answer by Sonal Otwani on 11 October 2022

Hi,

Yes, this use case can be supported through JSM.

Here are the points as part of requirement of the use case:

  • Snow will comments and attachments, so will sync comments as it is in JSM plus we will add one new comment which has all attachments
  • If there are new attachments then new attachments will be shown in new comment
  • e.g, You created incident with 2 comments and 3 attachments, in that case JSM will have 2 comments same as Snow and one additional comment which contains 3 attachment preview. Now if Snow tickets get update and have 1 comment and 2 attachment then in JSM you will have 2 more comments, one for comment of Snow and another for remaining 2 new attachments. so total 5 comments in JSM.

Here is the Script snippet:

issue.comments     = commentHelper.mergeComments(issue, replica)
issue.attachments  = attachmentHelper.mergeAttachments(issue, replica)

def newAttachments= replica.addedAttachments
def allNames=[]
  
newAttachments.collect {attachment ->
def fileName=attachment.filename

def matcher  = fileName =~ /([^\\s]+.(?i)(gif|jpe?g|tiff?|png|webp|bmp)$)/ 
if(matcher.find())
{
         allNames.add("!"+fileName+"|thumbnail!")
}
else
{
    allNames.add("[^"+fileName+"]")
  }
}
 def newComment=allNames.join(" ")
def allComments=commentHelper.addComment(newComment, false,issue.comments)
int i=0;
for(comment in allComments){
    i++;
    if(i==allComments.size()){
    comment.internal=false
    }
}
issue.comments =allComments

Let me know in case of any concerns.

Thanks,

Sonal