1
0
-1

Hello,


I have an issue with syncing issues from a remote site.


Issue type is not found. Please fill issue.typeName or issue.type parameter in script


Our site have other issue types, which I mean we have accounted for.

I've double checked our issue type names here: /rest/api/3/issuetype


I've tried different solutions both with issue type name and id, but nothing works. So I'm quite desperate.

Our incoming script for issue types is as follows:

if(firstSync){
    
    issue.projectKey   = "EUR"
    
    //map issue types between source and destination instances.
        def issueTypeMapping = [
    // "remote issue type" : "local issue type"
        "Story" : "Historie",
        "Epic" : "Gruppering",
        "Task" : "Oppgave",
        "Bug" : "Feil",
        "Sub-task" : "Deloppgave"
        ]
        issue.typeName = issueTypeMapping[replica.type?.name] ?: "Oppgave"
}

The remote site has this in outgoing script

replica.type           = issue.type

Does anyone have an idea?

I've used so many hours trying to figure this out now.


Regards,

Bjørnar

    CommentAdd your comment...

    3 answers

    1.  
      1
      0
      -1

      Hello, Bjørnar Nybruket 
      I can see from the remote replica the remote issue is both the Story and it has a parentId filled in
      So first the issue type is assigned through the mapping:

      def typeMapping = [
              // "remote issue type" : "local issue type"
              "Story" : "Historie",
              "Epic" : "Gruppering",
              "Task" : "Oppgave",
              "Bug" : "Feil",
              "Sub-task" : "Deloppgave"
      ]
      def remoteTypeName = replica.type?.name // "Story"
      
      def localType = typeMapping[remoteTypeName] ?: remoteTypeName // "Historie"
      ...
      issue.typeName = nodeHelper.getIssueType(localType)?.name?: "Oppgave" // "Historie"
      

      But later on it is reassigned due to the condition fullfilling:

      if(firstSync && replica.parentId){ 														// is true
          issue.typeName     = "deloppgave" //Make sure to use the right subtask type here.	// is reassigning the issue type
          def localParent = nodeHelper.getLocalIssueFromRemoteId(replica.parentId.toLong())
          if(localParent){
              issue.parentId = localParent.id
          } else {
              throw new com.exalate.api.exception.IssueTrackerException("Subtask cannot be created: parent issue with remote id " + replica.parentId + " was not found. Please make sure the parent issue is synchronized before resolving this error" )
          }
      }

      So I'd just recommend to remove this line:

      issue.typeName     = "deloppgave"

      And see if it works.
      Regards, Serhiy.

      1. Bjørnar Nybruket

        Thank you so much!
        This solved the issue.


        I didn't catch that it set other types of issues with parents as deloppgave (sub-task). 


        But, now everything works as intended. 

        Thank you again!

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

      I want to share my entire Incoming script, in case there is something wrong somewhere else in the script.


      def typeMapping = [
          // "remote issue type" : "local issue type"
              "Story" : "Historie",
              "Epic" : "Gruppering",
              "Task" : "Oppgave",
              "Bug" : "Feil",
              "Sub-task" : "Deloppgave"
              ]
      def remoteTypeName = replica.type?.name
      
      def localType = typeMapping[remoteTypeName] ?: remoteTypeName
      
      
      if(firstSync){
      
         // Set type name from source entity, if not found set a default
      
         issue.projectKey   = "EUR"
      
         issue.typeName = nodeHelper.getIssueType(localType)?.name?: "Oppgave"
      
      }
      
      issue.summary      = replica.summary
      issue.description  = replica.description
      //issue.comments     = commentHelper.mergeComments(issue, replica)
      issue.attachments  = attachmentHelper.mergeAttachments(issue, replica)
      
      //Dates
      issue.due = replica.due
      issue.customFields."Start Date" = replica.customFields."Start Date"
      
      // remoteIssueUrl is provided in the incoming sync script
      issue.customFields."RemoteIssue".value = remoteIssueUrl
      
      //Checking for ParentID for Subtasks
      if(firstSync && replica.parentId){
          issue.typeName     = "deloppgave" //Make sure to use the right subtask type here.
          def localParent = nodeHelper.getLocalIssueFromRemoteId(replica.parentId.toLong())
          if(localParent){
              issue.parentId = localParent.id
          } else {
             throw new com.exalate.api.exception.IssueTrackerException("Subtask cannot be created: parent issue with remote id " + replica.parentId + " was not found. Please make sure the parent issue is synchronized before resolving this error" )
          }
      }
      
      /*
      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 remoteAssignee = nodeHelper.getUserByEmail(replica.assignee?.email)
      if (nodeHelper.isUserAssignable(issue.projectKey, remoteAssignee)) {
        issue.assignee = remoteAssignee
      }
        else {
        issue.assignee = null
      }
      
      /*
      def defaultUser = nodeHelper.getUserByEmail("ks@septemberbi.no")
      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
      */
      issue.comments = commentHelper.mergeComments(issue, replica){ it.executor = nodeHelper.getUserByEmail(it.author?.email) }
      
      
      
      //Sync status for Epics 
      if (issue.typename == "Gruppering") {
          // ["remote status name" : "local status name"]
          def epicStatusMap = [ 
                  "On Hold" : "Pending",
                  "QA Test" : "For testing",
                  "UA Test" : "For testing",
                  "Approved" : "For testing",
                  "Not Approved" : "For testing",
                  "To Do" : "	Gjøremål",
                  "in Progress" : "under arbeid",
                  "Backlog" : "Gjøremål",
                  "Done" : "Ferdig",
          ]
          def epicStatusName = replica.customFields."Epic Status".value
          issue.setCustomFieldValue("Epic Status", epicStatusMap[epicStatusName] ?: "Gjøremål")
      } else {
          //Sync for all other statuses
          // ["remote status name" : "local status name"]
          def statusMap = [
                  "On Hold" : "Pending",
                  "QA Test" : "For testing",
                  "UA Test" : "For testing",
                  "Approved" : "For testing",
                  "Not Approved" : "For testing",
                  "Backlog" : "Gjøremål",
                  "in Progress" : "under arbeid",
                  "To Do" : "Gjøremål",
                  "Done" : "Ferdig"
          ]
          def remoteStatusName = replica.status.name
          issue.setStatus(statusMap[remoteStatusName] ?: "Gjøremål")
          Epic.receive()
      }
      //Custom Fields
      Epic.receive()
      1. Bjørnar Nybruket

        Here is the incoming remote replica:

        {
          "version": {
            "major": 1,
            "minor": 14,
            "patch": 0
          },
          "hubIssue": {
            "components": [],
            "attachments": [],
            "voters": [],
            "customFields": {},
            "eventTriggerContext": {},
            "description": "Agreements in place?",
            "project": {
              "idStr": "10001",
              "key": "DPR",
              "name": "Dataplatform and Reporting",
              "versions": [],
              "components": []
            },
            "watchers": [],
            "fixVersions": [],
            "id": "10075",
            "key": "DPR-9",
            "summary": "SLA Agreement",
            "comments": [],
            "internalMap": {},
            "reporter": {
              "key": "62309bc0442e0e0069eca714",
              "active": true,
              "email": "x",
              "displayName": "x"
            },
            "priority": {
              "id": "3",
              "name": "Medium"
            },
            "parentId": "10074",
            "labels": [],
            "customKeys": {
              "Epic Link": {
                "id": 10074,
                "key": "DPR-8"
              }
            },
            "workLogs": [],
            "issueType": {
              "id": "10001",
              "name": "Story"
            },
            "assignee": {
              "key": "60057042e64c95006fbde104",
              "active": true,
              "email": "x",
              "displayName": "x"
            },
            "affectedVersions": [],
            "entityProperties": {},
            "status": {
              "id": "10006",
              "name": "To Do",
              "description": "Ready to be done",
              "category": {
                "id": 2,
                "key": "new",
                "name": "To Do"
              }
            }
          },
          "issueUrl": "https://x.atlassian.net/browse/DPR-9"
        }
      CommentAdd your comment...
    3.  
      1
      0
      -1


      Hello,


      Can you please try this.


      def typeMapping = [
          // "remote issue type" : "local issue type"
              "Story" : "Historie",
              "Epic" : "Gruppering",
              "Task" : "Oppgave",
              "Bug" : "Feil",
              "Sub-task" : "Deloppgave"
              ]

      def remoteTypeName = replica.type?.name

      def localType = typeMapping[remoteTypeName] ?: remoteTypeName


      if(firstSync){

         // Set type name from source entity, if not found set a default

         issue.projectKey   = "EUR"

         issue.typeName = nodeHelper.getIssueType(localType)?.name?: "Oppgave"

      }


      Also make sure you are scripting the correct value of the issue types.


      Thanks,

      Dhiren

      1. Bjørnar Nybruket

        Hello Dhiren,


        Thank you, but this didn't solve the issue.


        I've checked both remote and local site for the correct values here /rest/api/3/issuetype.

        The site we sync from has the default issue type values, ours are changed.


        Here are the local issue types. Please tell me if I misunderstand anything.

        [{"self":"https://x.atlassian.net/rest/api/3/issuetype/10019","id":"10019","description":"Et lite stykke arbeid som er en del av en større oppgave.","iconUrl":"https://x.atlassian.net/rest/api/2/universal_avatar/view/type/issuetype/avatar/10316?size=medium","name":"Deloppgave","untranslatedName":"Deloppgave","subtask":true,"avatarId":10316,"hierarchyLevel":-1},
        
        {"self":"https://x.atlassian.net/rest/api/3/issuetype/10023","id":"10023","description":"Et lite, distinkt arbeidsstykke.","iconUrl":"https://x.atlassian.net/rest/api/2/universal_avatar/view/type/issuetype/avatar/10318?size=medium","name":"Oppgave","untranslatedName":"Oppgave","subtask":false,"avatarId":10318,"hierarchyLevel":0},
        
        {"self":"https://x.atlassian.net/rest/api/3/issuetype/10024","id":"10024","description":"Et problem eller en feil.","iconUrl":"https://x.atlassian.net/rest/api/2/universal_avatar/view/type/issuetype/avatar/10303?size=medium","name":"Feil","untranslatedName":"Feil","subtask":false,"avatarId":10303,"hierarchyLevel":0},
        
        {"self":"https://x.atlassian.net/rest/api/3/issuetype/10091","id":"10091","description":"Historier sporfunksjonalitet eller funksjoner uttrykt som brukermål.","iconUrl":"https://x.atlassian.net/images/icons/issuetypes/story.svg","name":"Historie","untranslatedName":"Historie","subtask":false,"hierarchyLevel":0},
        
        {"self":"https://x.atlassian.net/rest/api/3/issuetype/10026","id":"10026","description":"En samling relaterte feil, historier og oppgaver.","iconUrl":"https://x.atlassian.net/images/icons/issuetypes/epic.svg","name":"Gruppering","untranslatedName":"Gruppering","subtask":false,"hierarchyLevel":1}]
      CommentAdd your comment...