Add internal comment with date on outgoing sync

Originally asked by Mikael Bohlin on 24 November 2020 (original question)


Hi,

whats the easist way to add an internal comment on outgoing sync with date and time ?


Answer by Mikael Bohlin on 01 December 2020

Hi,

so the steps to set it up is:

  1. Add this to the incomming sync on JIRA side:
if (firstSync) {
   syncHelper.syncBackAfterProcessing()
}  
  
  
2. Add the custom field Sync Date of type Date  
3. Add the follwoing to our incomming sync ?
if (issue.customFields."Sync Date" == null) {
   issue.customFields."Sync Date".value = new Date()
}  
  
Step 3, would that not just update first sync date ?  
Regards  
Mikael B
  
  


Comments:

Francis Martens (Exalate) commented on 01 December 2020

How do you mean
> Step 3, would that not just update first sync date ?

What will happen.

  • A ticket gets exalated towards Jira.
  • Jira returns the confirmation with the syncBack
  • The zendesk updates the local custom field with the current date

The custom field will contain the date that the sync has been confirmed

Answer by Francis Martens (Exalate) on 24 November 2020

Hi Mikael Bohlin

  • Is this a sync zendesk to jira, and in what direction does the comment needs to flow
  • Does the comment body needs to be annotated on the outgoing side or the incoming side
  • What date/time are you alluding to

Francis


Comments:

Mikael Bohlin commented on 24 November 2020

Hi,

outgoing sync from Zendesk to JIRA. We would like it to be added as an internal comment in Zendesk only.

Mikael Bohlin commented on 24 November 2020

Hi,

date and time should be the date and time when the outgoing sync is started.

Regards

Mikael B

Francis Martens (Exalate) commented on 24 November 2020

> outgoing sync from Zendesk to JIRA. We would like it to be added as an internal comment in Zendesk only.

So - JIra comments need to be added as internal comment to zendesk

> date and time should be the date and time when the outgoing sync is started.
Would the date and time of when the comment was added to the Jira be ok?

Mikael Bohlin commented on 24 November 2020

Hi,

if the comment and date is the date when it was synced with JIRA. This is for getting a timestamp in Zendesk to be able to track when the sync is initiated.

Francis Martens (Exalate) commented on 24 November 2020

Regarding the time when the sync is initiated …

Add following to the replica

Outgoing

replica.customKeys."Sync date" = new Date()

This then can be used in the incoming to update a date (or add to the comment)

Incoming

// add a custom field of type date
issue.customFields."Sync Date".value = replica.customKeys."Sync date"
Mikael Bohlin commented on 25 November 2020

Hi,

i just want to add an internal comment in (In Zendesk) to the ticket that is synced . The comment should contain:

Ticket sync initiatet: “Date and Time”

OK?

Regards

Mikael

Mikael Bohlin commented on 25 November 2020

Hi,

can i write something like this in the outgoing syncrule:

issue.addedComments = replica.addedComments.collect{ c →

def Syncdate = newDate()
c.body = “Synk started:”+Syncdate
c
}
issue.comments = commentHelper.mergeComments(issue, replica, {it.internal = true})

Mikael Bohlin commented on 27 November 2020

Hi,

can i do like this ?: Will this work ?

1) Create a custom field in Zendesk “Sync Date”

2) Add the following to the outgoing sync script:

issue.customFields."Sync Date".value= newDate()
Francis Martens (Exalate) commented on 27 November 2020

Hi Mikael Bohlin

You can’t set the issue/ticket on the outgoing sync because this could create loops.
What you can do is to add a syncBackAfterprocessing in the incoming sync on Jira.

So

Incoming Sync - Jira

if (firstSync) {
   syncHelper.syncBackAfterProcessing()
}

on Zendesk, incoming sync, assume there is a custom field - Sync Date

Incoming Sync - Zendesk - Untested

if (issue.customFields."Sync Date" == null) {
   issue.customFields."Sync Date".value = new Date()
}

Hope this helps

Mikael Bohlin commented on 01 December 2020

Will this work for multiple updates ? That is if a ticket is synced serveral times ?

Francis Martens (Exalate) commented on 01 December 2020

Yes, that is why there is the if statement.
Once that it has been updated, it will remain.

If you would like to have the sync date updated each time that the sync happened, just remove the if statement

Mikael Bohlin commented on 02 December 2020

Ok,

but we want to use this for monitoring the last sync date. I guess we can remove the "first sync condition ?

Francis Martens (Exalate) commented on 04 December 2020

Yes - I assumed the requirement was ‘first sync’