Sync organization from Zendesk to Jira On Prem and set default value for non-matches

Originally asked by Sandra Campbell on 10 June 2022 (original question)


How do I sync Organization in Zendesk to a list field in Jira - and specify a default if the value is not found?

Sync works (with help from : Sync organization from Zendesk to Jira) if the value sent from Zendesk does exist in the Jira single select list field:

Zendesk outgoing sync

def orgId = issue.organization_id 
if(orgId){
  def orgName = httpClient.get("/api/v2/organizations/"+(long)orgId+".json").organization.name
  replica.customKeys."Organization" = orgName
}

Jira incoming sync

issue.customFields."OEMs".value = replica.customKeys.Organization 

Tried setting the default to “Others” like this but it did not work:

Jira incoming sync

issue.customFields."OEMs".value = replica.customKeys.Organization ?: "Others" 

thanks,

Sandra


Answer by Ezequiel Consorti on 30 June 2022

Hi Sandra,

I would suggest you to try the following script in your incoming Jira instance:

def orgOption = nodeHelper.getOption(issue, "Organization", replica.customKeys.Organization) 

if(orgOption == null){
    issue.customFields."Organization".value = nodeHelper.getOption(issue, "Organization", "Others")
}
else {
    issue.customFields."Organization".value = orgOption
}

the outgoing Zendesk doesn’t need to be modified.

Best,
Ezequiel