Geocode New Salesforce Accounts using Axway's AMPLIFY Integration Builder - Part 1 (FLOW EXPORT)
This file contains 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
{"id":25752,"name":"SF New Account Geocode","userId":21107,"accountId":18281,"createdDate":"2019-04-25T13:33:06Z","steps":[{"id":161398,"onSuccess":["updateNewAccountWithGPS"],"onFailure":[],"name":"constructBody","type":"script","properties":{"body":"var gps = steps.GetGPS.response.body;\n\nlet body={\n\tlb_sftest__Geocode__Longitude__s: gps.results[0].geometry.lng,\n\tlb_sftest__Geocode__Latitude__s: gps.results[0].geometry.lat\n}\n\ndone({body:body});"}},{"id":161422,"onSuccess":["isGPSReturned"],"onFailure":[],"name":"GetGPS","type":"httpRequest","properties":{"url":"${steps.prepareURL.url}","method":"GET"}},{"id":161395,"onSuccess":["isGPSPopulated"],"onFailure":[],"name":"getNewAccount","type":"elementRequest","properties":{"method":"GET","elementInstanceId":"${config.sfdc-in}","api":"/accounts/${trigger.event.objectId}"}},{"id":161716,"onSuccess":[],"onFailure":[],"name":"GPSAlreadyExistsLog","type":"script","properties":{"body":"console.log(\"GPS already populated\");"}},{"id":161722,"onSuccess":["prepareURL"],"onFailure":["noAddressFoundLog"],"name":"isAddressAvailable","type":"filter","properties":{"body":"var account = steps.getNewAccount.response.body;\n\nlet addressExists = account.ShippingStreet && account.ShippingCity && account.ShippingState && account.ShippingPostalCode && account.ShippingCountry;\n\nconsole.log(\"addressExists = \"+addressExists);\n\nif(addressExists) {\n done(true); \n} else {\n done(false); \n}"}},{"id":161715,"onSuccess":["isAddressAvailable"],"onFailure":["GPSAlreadyExistsLog"],"name":"isGPSPopulated","type":"filter","properties":{"body":"var account = steps.getNewAccount.response.body;\n\nlet lat = account.lb_sftest__Geocode__Latitude__s;\n\nlet lon = account.lb_sftest__Geocode__Longitude__s;\n\nconsole.log(lat);\n\nconsole.log(lon);\n\ndone(!lat && !lon);"}},{"id":161964,"onSuccess":["constructBody"],"onFailure":["noGPSLog"],"name":"isGPSReturned","type":"filter","properties":{"body":"var gps = steps.GetGPS.response.body;\n\nif(gps.hasOwnProperty('results')) {\n if(gps.results.length > 0) {\n if(gps.results[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 }\n} else {\n console.log('results does NOT exist');\n done(false);\n}"}},{"id":161713,"onSuccess":["getNewAccount"],"onFailure":["notNewAccountLog"],"name":"isNewAccount","type":"filter","properties":{"body":"let theEvent = trigger.event.eventType;\nlet theObject = trigger.event.objectType;\n\nconsole.log('theEvent = '+theEvent);\nconsole.log('theObject = '+theObject);\n\ndone((theEvent === 'CREATED') && (theObject === 'Account'));"}},{"id":161723,"onSuccess":[],"onFailure":[],"name":"noAddressFoundLog","type":"script","properties":{"body":"console.log(\"Account address not available so account cannot be geocoded\");\n\nconsole.log(\"Shipping Street, City, State, Zip and Country are ALL REQUIRED!!!\");"}},{"id":161965,"onSuccess":[],"onFailure":[],"name":"noGPSLog","type":"script","properties":{"body":"console.log('No GPS coordinates returned');"}},{"id":161714,"onSuccess":[],"onFailure":[],"name":"notNewAccountLog","type":"script","properties":{"body":"console.log('Not a new account. Maybe an update?');"}},{"id":161423,"onSuccess":["GetGPS"],"onFailure":[],"name":"prepareURL","type":"script","properties":{"body":"var account = steps.getNewAccount.response.body;\n\nlet url = 'https://api.opencagedata.com/geocode/v1/json'\n + '?'\n + 'key=' +encodeURIComponent('YOUR OPENCAGE API KEY')\n + '&q=' + encodeURIComponent(account.ShippingStreet) + ',' + encodeURIComponent(account.ShippingCity) + ',' +\n encodeURIComponent(account.ShippingState) + ',' +\n encodeURIComponent(account.ShippingPostalCode)\n + ',' +\n encodeURIComponent(account.ShippingCountry)\n + '&pretty=1'\n + '&no_annotations=1';\n\ndone({url:url});"}},{"id":161396,"onSuccess":[],"onFailure":[],"name":"updateNewAccountWithGPS","type":"elementRequest","properties":{"body":"${steps.constructBody.body}","method":"PATCH","api":"/accounts/${trigger.event.objectId}","elementInstanceId":"${config.sfdc-in}"}}],"triggers":[{"id":22972,"onSuccess":["isNewAccount"],"onFailure":[],"type":"event","async":true,"name":"trigger","properties":{"elementInstanceId":"${config.sfdc-in}"}}],"engine":"v3","active":true,"singleThreaded":false,"debugLoggingEnabled":true,"configuration":[{"id":44924,"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