# What is the current best way to handle syncing of Statuses including exceptions?

**URL:** <https://community.exalate.com/t/what-is-the-current-best-way-to-handle-syncing-of-statuses-including-exceptions/4204>\
**Category:** General Questions\
**Tags:** cloud-jira, migrated\_question\
**Created:** [November 4, 2024, 6:38am UTC](https://community.exalate.com/t/what-is-the-current-best-way-to-handle-syncing-of-statuses-including-exceptions/4204 "2024-11-04T06:38:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![xl8bot](https://dub1.discourse-cdn.com/flex018/user_avatar/community.exalate.com/xl8bot/32/324_2.png) [@xl8bot](https://community.exalate.com/u/xl8bot)\
**Post date:** [November 4, 2024, 6:38am UTC](https://community.exalate.com/t/what-is-the-current-best-way-to-handle-syncing-of-statuses-including-exceptions/4204/1 "2024-11-04T06:38:38Z")

</div>

_Originally asked by Daniel Szewczyk on 15 April 2020 [(original question)](https://oldcommunity.exalate.com/questions/11339081)_

* * *

Could you please advise how to improve the following code which we use to sync the statuses between two separate Jira instances and projects?  
Also, is there a way to prevent a situation where ticket would get out of sync if there is an unhandled status on either side?

Here’s the current code we use for handling the status syncs:

// the transitionmap maps remote statuses to transitions which needs to be activated locally  
def transitionMap = [  
“Open”:“Open”,  
“In Progress”:“In progress (2)”,  
“Waiting for customer”:“On Hold - Pending Customer”,  
“Escalated”:“Escalated”,  
“Reopened”:“Reopened”,  
“Closed”:“Closed”,  
]  
def resolutionMap = [  
“Done”:“Done”,  
“Fixed”:“Fixed”,  
“Won’t Do”:“Won’t Do”  
]  
/\* transition the issue to the corresponding status.  
\*\* If the remote status is null or the status is not found in the map,  
\*\* add a comment to the issue such that the configuration can be adapted.  
\*/  
if (replica.status == null ||  
replica.status.name == null ||  
transitionMap.get(replica.status.name) == null) {  
issue.comments = commentHelper.addComment(“Remote status is unknown or cannot be mapped - can’t handle it”, issue.comments)  
} else {  
workflowHelper.transition(issue, transitionMap.get(replica.status.name))  
if (replica.resolution != null && issue.resolution == null) {  
// use ‘done’ as resolution if the remote resolution is not found  
def targetResolutionName = resolutionMap[replica.resolution.name] ?: “Won’t Do”  
// nodeHelper.getResolution looks up the local resolution object based on the provided name  
issue.resolution = nodeHelper.getResolution(targetResolutionName)  
}  
else {  
return  
}  
}

Thanks in advance for your help!Source: [Jira Cloud](https://oldcommunity.exalate.com/pages/viewpage.action?pageId=3703235)_(old community)_

* * *

---

<div class="post-metadata">

**Author:** ![xl8bot](https://dub1.discourse-cdn.com/flex018/user_avatar/community.exalate.com/xl8bot/32/324_2.png) [@xl8bot](https://community.exalate.com/u/xl8bot)\
**Post date:** [November 4, 2024, 6:38am UTC](https://community.exalate.com/t/what-is-the-current-best-way-to-handle-syncing-of-statuses-including-exceptions/4204/2 "2024-11-04T06:38:39Z")

</div>

_Answer by André Leroy-Beaulieu Castro on 15 April 2020_

Hi Daniel,

I summarized your scenario with the newest syntax:

```auto
def statusMap = [
  "In Progress":"In progress (2)",
  "Waiting for customer":"On Hold - Pending Customer"
]

if (replica.status == null ||
    replica.status.name == null ||
    statusMap.get(replica.status.name) == null) {
  issue.comments = commentHelper.addComment("Remote status is unknown or cannot be mapped - can't handle it", issue.comments)
} else {
  issue.setStatus(statusMap[replica.status.name])
   if (replica.resolution != null && issue.resolution == null) {
      issue.resolution = replica.resolution }
   else return;
}

```

In this case, for the status mapping I removed all the lines that were mapping the same statuses, ex: “Done”:“Done”, because the default behavior is that if the status is not in the mapping, it tries to set that same status.

I removed the resolution mapping for the same reason and simplified the syntax.

Thanks,

André

* * *
