Field Validation Function - How can I run on a Deal CREATE as well as an UPDATE?

Field Validation Function - How can I run on a Deal CREATE as well as an UPDATE?

greetings.. I am running some address validation logic using an onChange() validation on the field.
When it runs during an edit/update Zoho CRM sends the Deal ID as part of the payload, so everything works.

When it runs during a new/create operation, there is not yet a record created.. so I am unable to parse the data field and populate the fields at this time.

How can I best accomplish this?

Code provided below for your reference:
  1. //
  2. crm_record = crmAPIRequest.toMap().get("record");
  3. if(crm_record.containKey("id"))
  4. {
  5. existing_record = true;
  6. job_id = crm_record.get("id").toLong();
  7. }
  8. else
  9. {
  10. existing_record = false;
  11. }
  12. //
  13. url_encoded_address = zoho.encryption.urlEncode(crm_record.get("full_home_address"));
  14. //
  15. // Retrieve the API key for LocationIQ out of the "CRM Variables"
  16. api_key = zoho.crm.getOrgVariable("locationiq_api_token");
  17. //
  18. // Run the validation using LocationIQ
  19. location_response = invokeurl
  20. [
  21. url :"https://us1.locationiq.com/v1/search?key=" + api_key + "&q=" + url_encoded_address + "&format=json&addressdetails=1&limit=1&countrycodes=us&normalizeaddress=1"
  22. type :GET
  23. detailed:true
  24. ];
  25. //
  26. class = location_response.get("responseText").get(0).get("class");
  27. place = location_response.get("responseText").get(0).get("place");
  28. //
  29. return_value = Map();
  30. //
  31. if(isNull(class))
  32. {
  33. return_value.put('status','error');
  34. return_value.put('message','Provided address does not validate');
  35. }
  36. else
  37. {
  38. if(existing_record)
  39. {
  40. address_components = location_response.get("responseText").get(0).get("address");
  41. //
  42. new_full_address = address_components.get("house_number") + " " + address_components.get("road") + ", " + address_components.get("city") + ", " + address_components.get("state") + " " + address_components.get("postcode");
  43. //
  44. updated_address_fields = Map();
  45. updated_address_fields.put("full_home_address",new_full_address);
  46. updated_address_fields.put("Description",new_full_address);
  47. updated_address_fields.put("address_house_number",address_components.get("house_number"));
  48. updated_address_fields.put("address_street",address_components.get("road"));
  49. updated_address_fields.put("address_city",address_components.get("city"));
  50. updated_address_fields.put("address_state",address_components.get("state"));
  51. updated_address_fields.put("address_zip",address_components.get("postcode"));
  52. updated_address_fields.put("Address_Validated",1);
  53. //
  54. update = zoho.crm.updateRecord("Deals",job_id,updated_address_fields);
  55. //
  56. }
  57. return_value.put('status','success');
  58. }
  59. //
  60. return return_value;

Thank you for any assistance you can provide.
- Joel