Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Geocode New Salesforce Accounts using Axway's AMPLIFY Integration Builder - Part 2 (ASSETS)
{"id":25958,"name":"SF New Account Geocode v2","userId":21107,"accountId":18281,"createdDate":"2019-05-06T21:22:28Z","steps":[{"id":163576,"onSuccess":["updateNewAccountWithGPS"],"onFailure":[],"name":"constructBody","type":"script","properties":{"body":"var gps = steps.getGPS.response.body;\n\nlet body={\n\tlon: gps[0].geometry.lng,\n\tlat: gps[0].geometry.lat\n}\n\ndone({body:body});"}},{"id":163589,"onSuccess":["isGPSReturned"],"onFailure":[],"name":"getGPS","type":"elementRequest","properties":{"elementInstanceId":"${config.geocoder}","query":"${steps.prepareQuery.query}","method":"GET","api":"/geocode"}},{"id":163577,"onSuccess":["isGPSReturned"],"onFailure":[],"name":"GetGPS","type":"httpRequest","properties":{"url":"${steps.prepareQuery.url}","method":"GET"}},{"id":163578,"onSuccess":["isGPSPopulated"],"onFailure":[],"name":"getNewAccount","type":"elementRequest","properties":{"elementInstanceId":"${config.sfdc-in}","method":"GET","api":"/AccountToGeocode/${trigger.event.objectId}"}},{"id":163579,"onSuccess":[],"onFailure":[],"name":"GPSAlreadyExistsLog","type":"script","properties":{"body":"console.log(\"GPS already populated\");"}},{"id":163580,"onSuccess":["prepareQuery"],"onFailure":["noAddressFoundLog"],"name":"isAddressAvailable","type":"filter","properties":{"body":"var account = steps.getNewAccount.response.body;\nlet addressExists = account.street && account.city && account.state && account.zip && account.country;\nconsole.log(\"addressExists = \"+addressExists);\nif(addressExists) {\n done(true);\n} else {\n done(false);\n}"}},{"id":163581,"onSuccess":["isAddressAvailable"],"onFailure":["GPSAlreadyExistsLog"],"name":"isGPSPopulated","type":"filter","properties":{"body":"var account = steps.getNewAccount.response.body;\nlet lat = account.lat;\nlet lon = account.lon;\nconsole.log(lat);\nconsole.log(lon);\ndone(!lat && !lon);"}},{"id":163582,"onSuccess":["constructBody"],"onFailure":["noGPSLog"],"name":"isGPSReturned","type":"filter","properties":{"body":"var gps = steps.getGPS.response.body;\n\nif(gps.length > 0) {\n if(gps[0].hasOwnProperty('geometry')) {\n console.log('lat/lon exists');\n done(true);\n } else {\n console.log('geometry does NOT exist');\n done(false);\n }\n} else {\n console.log('results has zero length');\n done(false);\n}"}},{"id":163583,"onSuccess":["getNewAccount"],"onFailure":["notNewAccountLog"],"name":"isNewAccount","type":"filter","properties":{"body":"let theEvent = trigger.event.eventType;\nlet theObject = trigger.event.objectType;\nconsole.log('theEvent = '+theEvent);\nconsole.log('theObject = '+theObject);\ndone((theEvent === 'CREATED') && (theObject === 'Account'));"}},{"id":163584,"onSuccess":[],"onFailure":[],"name":"noAddressFoundLog","type":"script","properties":{"body":"console.log(\"Account address not available so account cannot be geocoded\");\nconsole.log(\"Shipping Street, City, State, Zip and Country are ALL REQUIRED!!!\");"}},{"id":163585,"onSuccess":[],"onFailure":[],"name":"noGPSLog","type":"script","properties":{"body":"console.log('No GPS coordinates returned');"}},{"id":163586,"onSuccess":[],"onFailure":[],"name":"notNewAccountLog","type":"script","properties":{"body":"console.log('Not a new account. Maybe an update?');"}},{"id":163587,"onSuccess":["getGPS"],"onFailure":[],"name":"prepareQuery","type":"script","properties":{"body":"var account = steps.getNewAccount.response.body;\n\nlet address = encodeURIComponent(account.street) + ',' + encodeURIComponent(account.city) + ',' + encodeURIComponent(account.state) + ',' + encodeURIComponent(account.zip) + ',' + encodeURIComponent(account.country);\n\nlet query={\n query:address\n}\n\ndone({query:query});"}},{"id":163588,"onSuccess":[],"onFailure":[],"name":"updateNewAccountWithGPS","type":"elementRequest","properties":{"elementInstanceId":"${config.sfdc-in}","method":"PATCH","api":"/AccountToGeocode/${trigger.event.objectId}","body":"${steps.constructBody.body}"}}],"triggers":[{"id":23140,"onSuccess":["isNewAccount"],"onFailure":[],"type":"event","async":true,"name":"trigger","properties":{"elementInstanceId":"${config.sfdc-in}"}}],"engine":"v3","active":true,"singleThreaded":false,"debugLoggingEnabled":true,"configuration":[{"id":45385,"key":"geocoder","name":"geocoder","type":"elementInstance","required":true},{"id":45384,"key":"sfdc-in","name":"sfdc-in","type":"elementInstance","required":true}]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.