I'm trying to check of an existing customer number based on the domain of an Account. But I get the following error message:
I highlighted the line 24.
// Parameter: account_id
// Get the details of the account
account_id = input.account_id.toString();
account_details = zoho.crm.getRecordById("Accounts", account_id);
// Extract the required fields
erp_customer_number = account_details.get("Customer Number");
company_domain = account_details.get("Domain");
if(company_domain != null && company_domain != "" && (erp_customer_number == null || erp_customer_number == ""))
{
// Basic Authentication credentials
username = "xxx"; // Replace with your actual username
password = "xxx"; // Replace with your actual password
auth_header = "Basic " + zoho.encryption.base64Encode(username + ":" + password);
// Check if the customer already exists in the external system
api_url_check = "xxxx?$select=CardCode,EmailAddress&$filter=endswith(EmailAddress,'" + company_domain + "')&$orderby=CardCode";
headers_check = map();
headers_check.put("Content-Type", "application/json");
headers_check.put("Authorization", auth_header);
response_check = zoho.http.get(api_url_check, headers_check);
// Process the response
if(response_check.get("status").toNumber() == 200)
{
response_check_json = response_check.get("response").toString();
response_check_map = response_check_json.toMap();
if(response_check_map.containsKey("value") && response_check_map.get("value").size() > 0)
{
// Extract the customer number (CardCode) from the response
customer_info = response_check_map.get("value").get(0).toMap(); // Convert to map
customer_number = customer_info.get("CardCode").toString();
if(customer_number != null && customer_number != "")
{
// Update the account record with the customer number
update_map = map();
update_map.put("Customer Number", customer_number);
update_response = zoho.crm.updateRecord("Accounts", account_id, update_map);
if(update_response.get("code") != "SUCCESS")
{
// Error handling
info "Error updating account with customer number. Error: " + update_response.get("message");
}
else
{
info "Successfully updated account with customer number: " + customer_number;
}
}
else
{
info "Customer number not found in the response.";
}
}
else
{
info "No customer found with domain " + company_domain + ".";
}
}
else
{
// Error handling for check
info "Error checking customer existence. Status: " + response_check.get("status") + ", Response: " + response_check.get("response");
}
}
else
{
if(company_domain == null || company_domain == "")
{
info "No valid domain for account ID: " + account_id;
}
else
{
info "ERP customer number is already set for account ID: " + account_id;
}
}