How to Populate City and State Based on Zip Code
Task: We will be populating fields in Leads Module in Zoho CRM. The fields in this case are “City” and “State” based on the value of we put in Zip Code field.
Prerequisites (if applicable): Client Script and API Knowledge.
Instructions:
Step 1: Go on Create Lead Page. Click on Client Script button which is on the right side of the screen.
Step 2: Click on Add Script. Choose Field Event. Choose Zip Code Field. Select Event Type as OnChange.
Step 3: Start writing script.
var commonName = value;
console.log(commonName);
let url = "https://api.postalpincode.in/pincode/" + commonName;
let response = await fetch(url);
let commits = await response.json(); // read response body and parse as JSON
// console.log(commits);
let getpostdetails = commits[0];
// console.log(getpostdetails);
let getPostoffice = getpostdetails.PostOffice;
// let getPostoffice = getpostdetails[PostOffice];
console.log(getPostoffice);
let firstres = getPostoffice[0];
console.log(firstres);
let getblocknow = firstres.Block;
let getcirclenow = firstres.Circle;
let getDivisionnow = firstres.Division;
let district = firstres.District;
// ZDK.Page.getField("").setValue(getblocknow);
ZDK.Page.getField("State").setValue(getcirclenow);
ZDK.Page.getField("City").setValue(getblocknow);
Outcome: After this script is enabled, whenever someone puts in a legitimate zip code, the city and state is fetched using api and is auto populated in the respective fields.