Changing Task type after sync - Jira Cloud

Originally asked by Jonathan on 02 November 2021 (original question)


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

We have a number of task types as follows:

Local Replica
Task Task
Field Task Field Task
Digital Task Digital Task
Design Task Design Task
Sub-task Sub-task
Field Sub-task Field Sub-task
Digital Sub-task Digital Sub-task
Design Sub-task Design 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.


Comments:

Serhiy Onyshchenko commented on 03 November 2021

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.

Jonathan commented on 03 November 2021

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.

Elyashiv commented on 04 November 2021

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

Answer by Serhiy Onyshchenko on 04 November 2021

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


Comments:

Elyashiv commented on 07 November 2021

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

Serhiy Onyshchenko commented on 30 November 2021

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.

Answer by Richard K on 09 October 2023

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.

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


Answer by Jonathan on 05 November 2021

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!


This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.