Update local field when local issue execute sync

Originally asked by Peter Friberg on 19 May 2020 (original question)


For two synced issues, I need to find a way to show which issue was the one with the last update (the one who triggered sync the last time).
Considering a field “Last updated By” [ Instance 1 | Instance 2 ] at both issues.
The use case is two teams collaborating and they need a way to show who has the next action. Workflows are not compatible.
A thought was to set a local value at outgoing sync, but that seems not possible.
Any suggestions?


Answer by Juan Grases on 19 May 2020

You could send over the updated field:

//Outgoing:
replica.updated = issue.updated

And then update a custom field of type datetime on the incoming:

issue.customFields."Remote updated".value = replica.updated

Let me know if this works.


Comments:

Peter Friberg commented on 20 May 2020

Just to clarify: Suppose you mean that the Outgoing part is on “Instance 1”, and the incoming part is on “Instance 2”.

I can’t see how the user would have benefit of that, unless we can compare the “Instance 1” “Remote updated” with “Instance 2” “Remote updated”

What about this (I don’t dare to test it. Risk for infinite loops?):

Instance 1 incoming:

issue.customFields.``"last updated by"``.value = "Instance 2"

...

syncHelper.syncBackAfterProcessing()

Instance 2 incoming:

issue.customFields.``"last updated by"``.value = "Instance 1"

...

syncHelper.syncBackAfterProcessing()

Peter Friberg commented on 27 May 2020

Any comments on this Juan Grases

André Leroy-Beaulieu Castro commented on 02 July 2020

Hi Peter,

You can have the Outgoing line on both instances:

replica.updated = issue.updated

then on Incoming on both sides you can have this logic:

if (replica.updated > issue.updated) {
   issue.customFields."Remote updated".value = replica.updated
}

so that it only updates the field when the updated date received is newer than the current one in the custom field.

Let me know if this would work for you!

Thanks,

André