Code Snippet - Validate Account State By Zip
Here's a little snippet i came up with to check short states in your account records against min/max range to zip code.
It's also designed so it can be used as a mass update style button. I threw this together pretty quick and tested it on my test account data. Please use it with a test record before u put it in the wild. With slight modifications to the implementation you can add it to contacts or leads, whatever.
Instead of letting it pass on records it can't deal with you could add a tag to the record and use that to trigger a task or filter with it later to manually verify.
Just thought i'd share. Hope this helps someone.
- states ={
- "AK" : { "min" : "99501", "max" :"99950"},
- "WA" : { "min" : "98001", "max" :"99403"},
- "OR" : { "min" : "97001", "max" :"97920"},
- "HI" : { "min" : "96701", "max" :"96898"},
- "CA" : { "min" : "90001", "max" :"96162"},
- "NV" : { "min" : "88901", "max" :"89883"},
- "TX" : { "min" : "88510", "max" :"88589"},
- "NM" : { "min" : "87001", "max" :"88441"},
- "AZ" : { "min" : "85001", "max" :"86556"},
- "UT" : { "min" : "84001", "max" :"84784"},
- "ID" : { "min" : "83201", "max" :"83876"},
- "WY" : { "min" : "82001", "max" :"83128"},
- "CO" : { "min" : "80001", "max" :"81658"},
- "TX" : { "min" : "75503", "max" :"79999"},
- "AR" : { "min" : "75502", "max" :"75502"},
- "TX" : { "min" : "75001", "max" :"75501"},
- "OK" : { "min" : "73401", "max" :"74966"},
- "TX" : { "min" : "73301", "max" :"73301"},
- "OK" : { "min" : "73001", "max" :"73199"},
- "AR" : { "min" : "71601", "max" :"72959"},
- "LA" : { "min" : "71234", "max" :"71497"},
- "MS" : { "min" : "71233", "max" :"71233"},
- "LA" : { "min" : "70001", "max" :"71232"},
- "NE" : { "min" : "68122", "max" :"69367"},
- "IA" : { "min" : "68119", "max" :"68120"},
- "NE" : { "min" : "68001", "max" :"68118"},
- "KS" : { "min" : "66002", "max" :"67954"},
- "MO" : { "min" : "63001", "max" :"65899"},
- "IL" : { "min" : "60001", "max" :"62999"},
- "MT" : { "min" : "59001", "max" :"59937"},
- "ND" : { "min" : "58001", "max" :"58856"},
- "SD" : { "min" : "57001", "max" :"57799"},
- "MN" : { "min" : "55001", "max" :"56763"},
- "WI" : { "min" : "53001", "max" :"54990"},
- "IA" : { "min" : "50001", "max" :"52809"},
- "MI" : { "min" : "48001", "max" :"49971"},
- "IN" : { "min" : "46001", "max" :"47997"},
- "OH" : { "min" : "43001", "max" :"45999"},
- "KY" : { "min" : "40003", "max" :"42788"},
- "GA" : { "min" : "39901", "max" :"39901"},
- "MS" : { "min" : "38601", "max" :"39776"},
- "TN" : { "min" : "37010", "max" :"38589"},
- "AL" : { "min" : "35004", "max" :"36925"},
- "FL" : { "min" : "32004", "max" :"34997"},
- "GA" : { "min" : "30001", "max" :"31999"},
- "SC" : { "min" : "29001", "max" :"29948"},
- "NC" : { "min" : "27006", "max" :"28909"},
- "WV" : { "min" : "24701", "max" :"26886"},
- "VA" : { "min" : "22001", "max" :"24658"},
- "MD" : { "min" : "20812", "max" :"21930"},
- "DC" : { "min" : "20799", "max" :"20799"},
- "MD" : { "min" : "20335", "max" :"20797"},
- "MD" : { "min" : "20331", "max" :"20331"},
- "DC" : { "min" : "20042", "max" :"20599"},
- "VA" : { "min" : "20042", "max" :"20042"},
- "VA" : { "min" : "20040", "max" :"20041"},
- "VA" : { "min" : "20040", "max" :"20167"},
- "DC" : { "min" : "20001", "max" :"20039"},
- "DE" : { "min" : "19701", "max" :"19980"},
- "PA" : { "min" : "15001", "max" :"19640"},
- "NY" : { "min" : "10001", "max" :"14975"},
- "NJ" : { "min" : "7001", "max" :"8989"},
- "CT" : { "min" : "6401", "max" :"6928"},
- "NY" : { "min" : "6390", "max" :"6390"},
- "CT" : { "min" : "6001", "max" :"6389"},
- "VT" : { "min" : "5601", "max" :"5907"},
- "MA" : { "min" : "5501", "max" :"5544"},
- "VT" : { "min" : "5001", "max" :"5495"},
- "ME" : { "min" : "3901", "max" :"4992"},
- "NH" : { "min" : "3031", "max" :"3897"},
- "RI" : { "min" : "2801", "max" :"2940"},
- "MA" : { "min" : "1001", "max" :"2791"}
- };
-
- idStrList=List();
- if(input.id.contains("|||")){
- idStrList.addAll(input.id.toList("|||"));
- }else{
- idStrList.add(input.id);
- }
- for each recId in idStrList{
- rec = zoho.crm.getRecordById("Accounts", recId.toLong());
- recBillCode = ifnull(rec.get("Billing Code"), "");
- if(recBillCode.toString().matches("\b\d{4,5}\b")){
- recBillState = ifnull(rec.get("Billing State"), "");
- if(!recBillState.matches("\b[a-zA-Z]{2}\b")){
- state_iter = states.keys();
- for each st in state_iter {
- range = states.get(st).toMap();
- if(recBillCode.toLong() >= range.get("min").toLong() &&
- recBillCode.toLong() <= range.get("max").toLong()){
- upd = zoho.crm.updateRecord("Accounts", id.toString(), {"Billing State": st});
- }
- }
- }
- }
- }