How the get Jira Cloud custom dropdown and cascading select fields to work in the first sync

Originally asked by Petri Pihlajamaa on 01 April 2022 (original question)


Hi

I’m trying to get a connection between Zendesk and Jira Cloud to work and for the most part it does work. However i nthe firstsync when the Jira issue does not exist yet, I’m having trouble getting the custom fields of Dropdown and Cascading select to work. As the fields technically do not exist, the nodehelper for Getoption return as null value. How can I get it to work for the firstsync as well as any subsequent syncs? My relevant part of the code below.

The category variable is left as null as a result in the firstsync. It does work if the Jira issue is existing. How can I get it to work for the firstsync as well? First sync will always end up in the

//Get categories and subcategories
def SourceCategory = replica.customFields.“Cloud - Category”?.value?.value ?: “”

/*
Category mapping
*/
def categoryMapping = [
“” : “”,
“category_appointments_and_shifts” : “Appointments and shifts”,
“category_clients_and_patients” : “Clients and Patients”,
“category_consultation” : “Consultation”,
“category_finances” : “Finances”,
“category_general_functions” : “General functions”,
“category_inventory_management” : “Inventory Management”,
“category_laboratory_and_diagnostic_imaging” : “Laboratory and Diagnostic Imaging”,
“category_large_animal_features” : “Large animal features”,
“category_mobile_apps” : “Mobile Apps”,
“category_other” : “Other”,
“category_reporting” : “Reporting”,
“category_settings” : “Settings”,
]
def MappedCategory = categoryMapping[SourceCategory] ?: “”
def category = nodeHelper.getOption(
issue,
“Category”,
MappedCategory
)

def mappedSubCategory = subCategoryMapping[sourceSubCategory] ?: “”

if(category != “” && category != null) {
def subCategory = category.childOptions.find{it.value == mappedSubCategory}
if ( category != “” && (sourceSubCategory == “” || subCategory != “”)) {
issue.customFields.“Category”?.value = nodeHelper.getCascadingSelect(
category,
subCategory
)
}
else if (SourceCategory == null) {
issue.customFields.“Category”?.value = null
}
}
else {
issue.customFields.“Category”?.value = null
}