How to sync 2 different statuses in one based on transitions

Originally asked by Arto Kovalainen on 31 August 2020 (original question)


I have Server JIRA with following workflow:

And connected Cloud JIRA with following:

How to achieve:

  • If status transitioned in Server from Open to In progress
    • Then Map status In progress to Investigation in Cloud JIRA
  • If any other transition to In progress in Server (eg. from Done to In progress or from Pending to In progress (transition is missing in the picture but don’t mind that)
    • Then Map status In progress to Selected for Develepment in JIRA cloud

?

Optionally

  • If status transitioned in Server from Open to In progress
    • Do nothing in JIRA Cloud workflow
  • If any other transition to In progress in Server (eg. from Done to In progress or from Pending to In progress (transition is missing in the picture but don’t mind that)
    • Then Map status In progress to Selected for Develepment in JIRA cloud

?


Answer by Francis Martens (Exalate) on 04 September 2020

Hi Arto Kovalainen

You can construct it as follows using the previous replica named as ‘previous’.
It contains the message that was sent before the current one. If the status was sent then, you will be able to know what the originating status was.

if (replica.status.name == "In Progress") {
   issue.setStatus(previous?.status.name == "Open" ? "In Progress" : "Selected for Development")
}


Note that the previous replica is not set when exalating an issue, so you will have to use the safe navigation operator after previous, or distinguish using the firstSync boolean.