Issue.created in Zendesk outgoing script shows as null

Originally asked by Sandra Campbell on 07 July 2023 (original question)


I need to get the the Zendesk ticket created date and populate to a custom date field in Jira On Prem.

However the issue.created value does not seem to work in Zendesk. The Exalate doco (How to Sync CreatedDate Field? | Exalate Documentation) doesn’t show Zendesk in the list of system labels at the top of the screen. But I tried it anyway.

When I put this in the Zendesk outgoing script:

replica.created = issue.created
debug.error("replica.created = " + replica.created)

I get this error message:

Sync rules error
replica.created = null

Am I doing something wrong? Or is there another way/command to get the date a Zendesk ticket is created?

thanks, Sandra


Answer by Syed Majid Hassan on 10 July 2023

Hi Sandra Campbell,

Using the following in the Zendesk outgoing script should suffice:

def res = httpClient.get("/api/v2/tickets/${issue.key}.json")
def created_at = res.ticket.created_at 
debug.error("${created_at}")

but you need to be careful about the format you receive it on the destination end. You might need to manipulate it a little (not sure as I have not tested it end to end).

Hope it helps.

Thanks

Majid


Comments:

Sandra Campbell commented on 11 July 2023

hi Syed Majid Hassan

that got me the required date info, and yes it does need some manipulation to get it into the right format,

appreciate your help

thanks,

Sandra

Sandra Campbell commented on 11 July 2023

This is what ended up working …

Zendesk outgoing script

def res = httpClient.get("/api/v2/tickets/${issue.key}.json")
def inputDate = res.ticket.created_at
replica."Date created" = inputDate

Jira On Prem incoming script

import java.time.Instant
import java.time.LocalDateTime
import java.time.ZoneOffset
import java.time.format.DateTimeFormatter

def inputDate = replica."Date created"
def formatter = DateTimeFormatter.ISO_INSTANT
def instant = Instant.from(formatter.parse(inputDate))
def epochTimestamp = instant.toEpochMilli()
issue.customFields."ZD Created date".value = epochTimestamp
Syed Majid Hassan commented on 11 July 2023

Awesome! Ye I feared that date formatting thing.

Glad to see it work.

Thanks for sharing

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.