Handle Description Mentions from JiraCloud to Jira server

Originally asked by Vinay on 01 October 2021 (original question)


Hi,

We have few issues where description has users mentions in Jira Cloud something like this

but [~accountid:5d1463a784d7dc0c52fda8f4] reopened it…

Jira Cloud : but Username reopened it…

Jira Server : but [~accountid:5d1463a784d7dc0c52fda8f4] reopened it…

How to handle user mentions in the script to convert it to Displayname in Jira Server


Answer by Vinay on 05 October 2021

I have modified the code slightly and it worked.

def matcher_des = issue.description =~ /\[~accountid:([\w:-]+)\]/
def description = issue.description
matcher_des.each {
target = nodeHelper.getUser(it[1])?.displayName
description = description.replace(it[0], target)
}
replica.description = description


Answer by Mariia Onyshchenko on 01 October 2021

Hi Vinay,
This article might help you:

https://community.atlassian.com/t5/Agile-articles/How-to-sanitize-mentions-when-synchronizing-issues/ba-p/1141139

you could replace every mention sent from cloud with email:

/*
** This code snippet illustrates how mentions can be replaced with the actual name of the mentionee
** Use this in a data filter
*/


replica.comments       = issue.comments.collect {
              comment ->
              

              def matcher  = comment.body =~ /\[~(\w+)\]/
              def newCommentBody = comment.body

              matcher.each {
                  target = "[~$nodeHelper.getUser(it[1])?.email]"
                  newCommentBody = newCommentBody.replace(it[0], target)
              }

              comment.body = newCommentBody
              comment
}

And then use similar logic on server to lookup a user using email
Please, let me know if this helps


Comments:

Vinay commented on 01 October 2021

Mariia Onyshchenko , I have seen that article, but I need the script for description user mentions not for comments!

Ariel Aguilar commented on 01 October 2021

Hi Vinay,

For description, you can try adding this to the Outgoing script:

def matcher  = issue.description =~ /\[~(\w+)\]/
def description = issue.description
matcher.each {
   target = "[~$nodeHelper.getUser(it[1])?.email]"
  description = description.replace(it[0], target)
}
replica.description = description

Let me know if this works for you.

Kind regards,

Ariel

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.