Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Zoho CRM client script address verification via client script
// Demo: https://www.youtube.com/watch?v=oA2EV7Gz5NM
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