1
0
-1

We were recently requested by a client to provide scripts which would sync user mentions from Jira Cloud comments to Salesforce chatter feed comments. 

    CommentAdd your comment...

    1 answer

    1.  
      1
      0
      -1

      There are many approaches that can be taken to solve this use case, but we used the following in this case:


      Step 1: Read the mention in the Jira comment and replace it with the users email address

      Jira Outgoing Script
      replica.comments = issue.comments.collect {
          comment ->
          def matcher  = comment.body =~ /\[~accountid:([\w:-]+)\]/
          def newCommentBody = comment.body
          matcher.each {
              target = nodeHelper.getUser(it[1])?.email
              newCommentBody = newCommentBody.replace(it[0],target)
          }
       
          comment.body = newCommentBody
          comment
      }

      Step 2: Find the email address from replica.comments and call a Salesforce endpoint to add the correct user mention to that comment

      Salesforce Incoming Script
      def commentMap = [
         "mathieu.lepoutre@idalko.com" : "0057Q000006fOOTQA2",
         "syed.majid.hassan@idalko.com" : "0057Q000006fOOOQA2"
         ]
      replica.comments.collect {
          comment ->
          def matcher  = comment.body =~ /([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)/
          def newCommentBody = comment.body
          matcher.each {
              newCommentBody = newCommentBody.replace(it[0],"")
              def res = httpClient.post("/services/data/v54.0/chatter/feed-elements", \
              "{\"body\":{\"messageSegments\":[{\"type\":\"Text\", \"text\":\"${newCommentBody} \" },{\"type\":\"Mention\", \"id\":\"${commentMap[it[0]]}\"}]},\"feedElementType\":\"FeedItem\",\"subjectId\":\"${entity.Id}\"}")
          }
      }

      The commentMap above is needed to correlate the Salesforce accountId to the incoming email address. This can be replaced if you have the same email address configured on both ends and are willing to make some effort looking for the correct account on Salesforce account programmatically. 


      A video demonstration of the scripts in action is attached here:


      Thanks
      Majid

        CommentAdd your comment...