Stop sync if defect is closed

Originally asked by SANDEEP ADE on 17 January 2020 (original question)


Hi ,

If i want to stop sync from alm end when defect is closed ,what should be the code ?

i want to update the defect in Jira from alm only if the status of the defect is not closed


Answer by Francis Martens (Exalate) on 17 January 2020

There will be no synchronisation if the message (replica) is empty

For instance if you would add following code to the outgoing sync - you should be all set

Untested

if (defect.status == "Closed") {
   return
}


...

Let us know how it goes


Comments:

SANDEEP ADE commented on 17 January 2020

But in this case i want to update current status and from next update i wanted to stop,

Ex:In ALM ,i changed status to Closed which should update the status in JIRA as closed

once that happens it should then stop next record updates because the defect is closed ,which means the Closed status should be updated in JIRA and once it is done ,it should block further updates

How to achieve that?

Francis Martens (Exalate) commented on 17 January 2020

An approach is to keep track of the Jira Status.

The condition would be then

outgoing sync on the hp side

if (defect.status == "Closed" and defect.customKeys."JiraStatus" == "Closed") {
   return
}

...

replica.status = defect.status

Now there is a bit of complexity here.

Whenever the exalate changes the status of the Jira issue to closed, that change will not be synced back.

So, on the Jira side, you will need to trigger a sync back - using the syncBackAfterProcessing method

Something like

Incoming Sync - Jira side

if (replica.status == "Closed" && issue.status?.name != "Closed")  {
   // close the issue and sync this back to hp such that the status is updated
   workflowHelper.transition("Close", issue)
   syncHelper.syncBackAfterProcssing(syncRequest)
}

It is easy to create infinite loops over 2 systems with the syncBackAfterProcessing - be sure to break the possible chain.