Conditional Sync of Request Participants and Watchers in Jira Service Management from Jira Data Center

Originally asked by Jaspreet Kaur on 22 September 2023 (original question)


I’m looking to sync our Watchers field in Jira DC (on-prem) to our Jira Service Management instance (Cloud). Our Watchers include both internal and externals users in Jira DC but in JSM, I need these users to be added to Watchers (if internal) and Request Participants (if external).

I’m able to get all Watchers to Request Participants using this:

  
issue.customFields."Request participants"?.value = replica.watchers.collect{w -> nodeHelper.getUserByEmail(w.email)}

I’m not sure how best it would be to filter on the replica.watchers to create two collections or how to do an if statement to compare the email within the collect.


Answer by Javier Pozuelo on 03 October 2023

The following solution works for syncs between Jira instances, including a sync between Jira On-premise → Jira Cloud.

Place the following in Incoming Sync of your Jira Cloud.

def localWatchers = []replica.watchers.each { w ->    def _localW = nodeHelper.getUserByEmail(w.email)    if (_localW != null) {        localWatchers << _localW  // Add to the local watchers list if the user exists    }}issue.watchers = localWatchers 

Regards,

Javier Pozuelo


Answer by Javier Pozuelo on 26 September 2023

Hello Jaspreet,

Add the following code in the Incoming Sync of your Jira Service Management instance (Cloud).

issue.watchers = replica.watchers
        .each { w ->
    def _localW = nodeHelper.getUserByEmail(w.email)
    if (_localW == null) {
        throw new com.exalate.api.exception.IssueTrackerException(
                "Could not find user `${w.email}`"
        )
    }
}

Kind regards,

Javier Pozuelo


Comments:

Javier Pozuelo commented on 03 October 2023

This solution works for a sync between Jira Cloud instances.

Answer by Jaspreet Kaur on 22 September 2023

Looks like this is the solution if it helps anyone

Add this to the Source outgoing sync:

replica.watchers       = issue.watchers.findAll{it.email.contains("@grantstreet.com")}
replica.requestParticipants = issue.watchers.findAll{!it.email.contains("@grantstreet.com")}

Answer by Jaspreet Kaur on 22 September 2023

I tried this but I’m not sure how to format for it to keep trying and not throw an error.

issue.watchers = replica.watchers.collect{w -> 
String userEmail = w.email
if(userEmail.contains("@grantstreet.com"))
{nodeHelper.getUserByEmail(w.email)}
else
   {throw new com.exalate.api.exception.IssueTrackerException("Not External User")}
}

Comments:

Ariel Aguilar commented on 28 September 2023

Have you tried?

issue.watchers = replica.watchers.collect{w ->
String userEmail = w.email
if(userEmail.contains("@grantstreet.com"))
{nodeHelper.getUserByEmail(w.email)}
else
   return
}