Skip to content

Instantly share code, notes, and snippets.

@jeznag
Created September 4, 2021 08:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jeznag/8f8d8cba83054a851d50cc2e0d46bb40 to your computer and use it in GitHub Desktop.
Save jeznag/8f8d8cba83054a851d50cc2e0d46bb40 to your computer and use it in GitHub Desktop.
Zoho CRM client script address verification via client script
const street = ZDK.Page.getField('Street').getValue();
const city = ZDK.Page.getField('City').getValue();
const zipCode = ZDK.Page.getField('Zip_Code').getValue();
const country = ZDK.Page.getField('Country').getValue();
const state = ZDK.Page.getField('State').getValue();
const address = `${street} ${city} ${state} ${zipCode} ${country}`;
const url = `http://api.positionstack.com/v1/forward`
const result = ZDK.HTTP.request({
url,
method: 'GET',
parameters: {
access_key: '******',
query: address
}
}).getResponse();
const { data: geocodingResult } = JSON.parse(result);
if (geocodingResult.length) {
const geocodedAddress = geocodingResult[0].label;
const updateAddress = ZDK.Client.showConfirmation(`🤖 I looked up the address and here is how I think it should be formatted: ${geocodedAddress}`, 'You nailed it 🤖', `You suck 🤖 I'll use mine`);
if (updateAddress) {
ZDK.Page.getField('Street').setValue(geocodingResult[0].name);
ZDK.Page.getField('City').setValue(geocodingResult[0].county);
ZDK.Page.getField('Zip_Code').setValue(geocodingResult[0].postal_code);
ZDK.Page.getField('Country').setValue(geocodingResult[0].country);
ZDK.Page.getField('State').setValue(geocodingResult[0].region_code);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment