1
0
-1

Task types will not update when a user changes the type.


We have a number of task types as follows:

LocalReplica
TaskTask
Field TaskField Task
Digital TaskDigital Task
Design TaskDesign Task


Sub-taskSub-task
Field Sub-taskField Sub-task
Digital Sub-taskDigital Sub-task
Design Sub-taskDesign Sub-task


These are syncing but when an user identifies that a task is the wrong sort and changes it, ie from Digital to Field. This change is not synced. 


Tasks are syncing using incoming code: 

if(firstSync){
   issue.projectKey   = "*PROJkey*" 
   // Set type name from source issue, if not found set a default
   issue.typeName     = nodeHelper.getIssueType(replica.type?.name, issue.projectKey)?.name ?: "Task"
}
issue.typeName = nodeHelper.getIssueType(replica.type?.name, issue.projectKey ?: issue.project?.key)?.name ?: nodeHelper.getIssueType("incident")?.name



Subtasks are set up using : https://docs.idalko.com/exalate/display/ED/How+to+sync+tasks+and+subtasks+in+Jira+Cloud


incoming code:

if(firstSync && replica.parentId){
    issue.typeName     = "Sub-task" //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" )
    }
}

This one is copied for each sub-task type. 

  1. Serhiy Onyshchenko

    Hello, Jonathan ,
    Thanks for raising this on community.
    Do all Task types have the same workflow (do all the sub-task types have the same workflow as well)?
    Regards, Serhiy.

  2. Jonathan

    Hi Serhiy,


    Yes the only difference between them all is the name and icon. It is simply to be able to easier distinguish the different work for teams and quicker filtering by Task type.

  3. Elyashiv

    Hi Serhiy Onyshchenko,
    We have the same need.
    What do we need to change in the code so the sync rule will sync the issue type too?

    Are there any other requirements besides that the workflows of both issue-types will be the same?

    Thanks,

    Elyashiv

CommentAdd your comment...

3 answers

  1.  
    2
    1
    0

    Hey, Jonathan , Elyashiv 
    Answering the questions you had:


    These are syncing but when an user identifies that a task is the wrong sort and changes it, ie from Digital to Field. This change is not synced.

    You just need to replace your line:

    issue.typeName = nodeHelper.getIssueType(replica.type?.name, issue.projectKey ?: issue.project?.key)?.name ?: nodeHelper.getIssueType("incident")?.name

    with

    if (!firstSync) {
        issue.type = nodeHelper.getIssueType(replica.type?.name, issue.projectKey ?: issue.project?.key) ?: nodeHelper.getIssueType("incident", issue.projectKey ?: issue.project?.key)
    }


    Are there any other requirements besides that the workflows of both issue-types will be the same?

    No other requirements but the workflows being same.


    Here's a video showing how this works in action:


    P.S.

    This one is copied for each sub-task type.

    to optimize the number of lines copied, I'd suggest to change from

    if(firstSync && replica.parentId && replica.type.name == "Sub-task"){
        issue.typeName     = "Sub-task" //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" )
        }
    }
    if(firstSync && replica.parentId && replica.type.name == "Other Subtask"){
        issue.typeName     = "Another Subtask" //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" )
        }
    }

    to

    if(firstSync && replica.parentId){
    	def mapping = [
    		//remote issue type : local issue type
    		"Sub-task":"Sub-task",
    		"Other Subtask":"Another Subtask"
    	]
        issue.typeName     = mapping[replica.type.name] ?: replica.type.name //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" )
        }
    }



    Happy Exalating!
    Serhiy

    1. Elyashiv

      Hi Serhiy Onyshchenko,

      Thanks for the detailed answer.

      For my Jira instance, the suggestion didn't work.

      I'm trying to sync between Jira Cloud & Jira Server, workflows are exactly the same.

      issues are created in the cloud and synced to server. I added to the {Server - outgoing} & {Cloud - incoming} the line:


      issue.type = nodeHelper.getIssueType(replica.type?.name, issue.projectKey ?: issue.project?.key) ?: nodeHelper.getIssueType("Bug", issue.projectKey ?: issue.project?.key)
      }



      Thanks

    2. Serhiy Onyshchenko

      Hello, Elyashiv , again, very sorry for being sluggish on the response.
      You won't have to add it for the outgoing sync on Jira Server, feel free to remove it from there.
      On the Jira Cloud side - do the issue types you change between have the same workflow?
      Regards, Serhiy.

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

    Hi!

    We faced the same problem with the sync of changing issue types and this solution helped us to solve it. Thank you!


    But I have 2 questions about the script.

    1. issue.typeName     = nodeHelper.getIssueType(replica.type?.name, issue.projectKey)?.name ?: "Task"


      Why is "Task" defined? Do I have to define an issue type?

    2. issue.typeName = nodeHelper.getIssueType(replica.type?.name, issue.projectKey ?: issue.project?.key)?.name ?: nodeHelper.getIssueType("incident")?.name


      What is "incident" in this line?
      I don't see "incident" issue type in this post.
      I copied the script to our exalate connection and it works fine and we don't have "incident" issue type.


    Best regards,

    Richard

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

      Serhiy Onyshchenko,


      Thank you so much for your help. I have tested the main issue type change and it is wonderful (smile)


      Will get onto the subtask code optimisation shortly. 


      thanks for the support, have a great day! 

        CommentAdd your comment...