How to Populate City and State Based on Zip Code

How to Populate City and State Based on Zip Code

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.




    • Related Articles

    • How to Create a Task and Populate a Custom Date/Time Field with a TAT.

      Task: We first create a task based on lead status change. We will be then populating a custom date/time field which can be used as a TAT. The TAT will be adjusted according to the users shift hours and working days. Prerequisites (if applicable): ...
    • How to Create, Update, Read and Delete records in Zoho CRM.

      If you want to Create, Update, Read and Delete records in Zoho CRM in any module, please use the following code for the same: Code: var commonname = value.id; var acc = ZDK.Apps.CRM.Accounts.fetchById(commonname); var phone = acc.MobileNo; var email ...
    • How to set a field as read-only using client script

      Task: Writing a client script for a different inbuild function based on different seniors/events. Prerequisites (if applicable): You should have a basic understanding of how to create and manage client scripts in your application. Instructions: Step ...
    • How to auto capture date in any module of Zoho CRM (T+15)

      User wants the date should capture as T+15 in any module of Zoho CRM. Deluge Code: Cdate = zoho.currentdate.addDay(15).toString("YYYY-MM-dd"); Zoho Link: https://www.zoho.com/deluge/help/functions/date-time.html
    • How to fetch & update records in Sub Form in Zoho CRM.

      If you want to fetch & update records in Sub Form in any module of Zoho CRM. Please use the following code: Deluge Code: data = zoho.crm.getRecordById("Asset_Master",ID);//fetchRecord sub = data.get("Contract_Information");//AccessSubbform ...