1
0
-1

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.

    CommentAdd your comment...

    4 answers

    1.  
      1
      0
      -1

      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

        CommentAdd your comment...
      1.  
        1
        0
        -1

        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

        1. Javier Pozuelo

          This solution works for a sync between Jira Cloud instances.

        CommentAdd your comment...
      2.  
        1
        0
        -1

        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")}
          CommentAdd your comment...
        1.  
          1
          0
          -1

          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")}
          }
          1. Ariel Aguilar

            Have you tried?


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