1
0
-1

We are trying to configure the logic so a ServiceNow incident creates a Jira Bug and a ServiceNow agile/story ticket creates a Jira Story. 


We’d also like to do the reverse.  We’ve tried a variety of combinations, but can’t quite get it right. 

    CommentAdd your comment...

    1 answer

    1.  
      1
      0
      -1

      Hello, Jose Lobo , thanks for asking on community!
      It's basically a combination of these guides:

      (Please note, that this is a wide table)

      ScriptSNOWJira
      ​Outgoing sync
      replica.summary = entity.short_description
      replica.description = entity.description
      replica.comments = entity.comments
      replica.attachments = entity.attachments
      replica.entityType = entityType
      replica.key = entity.key

      replica.key            = issue.key
      replica.type           = issue.type
      replica.assignee       = issue.assignee
      replica.reporter       = issue.reporter
      replica.summary        = issue.summary
      replica.description    = issue.description
      replica.labels         = issue.labels
      replica.comments       = issue.comments
      replica.resolution     = issue.resolution
      replica.status         = issue.status
      replica.parentId       = issue.parentId
      replica.priority       = issue.priority
      replica.attachments    = issue.attachments
      replica.project        = issue.project
      
      //Comment these lines out if you are interested in sending the full list of versions and components of the source project. 
      replica.project.versions = []
      replica.project.components = []

      Incoming sync
      if(replica.type.name == "Bug") { //if the received issue typeName is Bug create Incident on ServiceNow
          if(firstSync) {
              incident.correlation_id = replica.key
          }
          incident.short_description = replica.summary
          incident.description = replica.description
          incident.comments += replica.addedComments
          incident.attachments += replica.addedAttachments
      } else if (replica.type.name == "Story") {
          if(firstSync) {
              story.correlation_id = replica.key
          }
          story.short_description = replica.summary
          story.description = replica.description
          story.comments += replica.addedComments
          story.attachments += replica.addedAttachments
      }
      
      
      if(firstSync){
          if ("story".equalsIgnoreCase(replica.entityType)) {
              issue.typeName     = "Story"
          } else if ("incident".equalsIgnoreCase(replica.entityType)) {
              issue.typeName = "Bug"
          } else {
              // Don't sync anything but stories and bugs
              return 
          }
          // use your project instead
          issue.projectKey   = "SCRM"
      }
      issue.summary      = replica.summary
      issue.description  = replica.description
      issue.comments     = commentHelper.mergeComments(issue, replica)
      issue.attachments  = attachmentHelper.mergeAttachments(issue, replica)
      issue.labels       = replica.labels
      
      /*
      User Synchronization (Assignee/Reporter)
      
      Set a Reporter/Assignee from the source side, if the user can't be found set a default user
      You can use this approach for custom fields of type User
      def defaultUser = nodeHelper.getUserByEmail("default@idalko.com")
      issue.reporter = nodeHelper.getUserByEmail(replica.reporter?.email) ?: defaultUser
      issue.assignee = nodeHelper.getUserByEmail(replica.assignee?.email) ?: defaultUser
      */
      
      /*
      Comment Synchronization
      
      Sync comments with the original author if the user exists in the local instance
      Remove original Comments sync line if you are using this approach
      issue.comments = commentHelper.mergeComments(issue, replica){ it.executor = nodeHelper.getUserByEmail(it.author?.email) }
      */
      
      /*
      Status Synchronization
      
      Sync status according to the mapping [remote issue status: local issue status]
      If statuses are the same on both sides don't include them in the mapping
      def statusMapping = ["Open":"New", "To Do":"Backlog"]
      def remoteStatusName = replica.status.name
      issue.setStatus(statusMapping[remoteStatusName] ?: remoteStatusName)
      */
      
      /*
      Custom Fields
      
      This line will sync Text, Option(s), Number, Date, Organization, and Labels CFs
      For other types of CF check documentation
      issue.customFields."CF Name".value = replica.customFields."CF Name".value
      */
      
      

      Let me know how it goes,
      Regards, Serhiy.

        CommentAdd your comment...