-
-
Save cliffordp/a6970bca63553f0f5d46b9cdd5ab27b1 to your computer and use it in GitHub Desktop.
Zoho CRM client script address verification via client script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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