This repository has been archived by the owner on Feb 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createWaylayAlarmRecordSalesForce.json
25 lines (25 loc) · 2.64 KB
/
createWaylayAlarmRecordSalesForce.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
{
"name": "createWaylayAlarmRecordSalesForce",
"version": "0.0.28",
"type": "actuator",
"script": "const jsforce = require('jsforce')\nconst pify = require('pify')\nconst Waylay = require('@waylay/client')\nconst _ = require('lodash')\n\n// INSTANCE URL below!!\n// asset: 02i1i000000h1OnAAI\n// account: 0011i00000A2MktAAF\n\nasync function main () {\n const customObject = cleanObject({\n Name: options.requiredProperties.name,\n Asset__c: options.requiredProperties.assetID,\n Account__c: options.requiredProperties.accountID,\n Description__c: options.requiredProperties.description || ''\n })\n\n if (!customObject.Asset__c) {\n throw new Error('No asset id provided')\n }\n\n if (!customObject.Account__c) {\n throw new Error('No account id provided')\n }\n\n const conn = await getSalesforceConnection()\n const SfEvent = pify(conn.sobject('WaylayAlarm__c'))\n\n const res = await SfEvent.create(customObject)\n\n send(null, { message: JSON.stringify(res) })\n}\n\nasync function getSalesforceConnection () {\n try {\n const waylayClient = new Waylay({\n token: options.globalSettings.waylayToken\n })\n\n const { access_token: accessToken } = await waylayClient.hoard.getTokens('salesforce', { scope: 'organisation' })\n\n if (!accessToken) {\n throw new Error('No user or token provided via Hoard service')\n }\n\n const jsclient = new jsforce.Connection({\n instanceUrl: 'https://eu26.salesforce.com',\n accessToken\n })\n\n return jsclient\n } catch (error) {\n throw new Error(`error: ${error} \\n possible solution: Connect Salesforce through the connections`)\n }\n}\n\n/**\n * remove empty values in object before sending to salesforce\n */\nfunction cleanObject (object) {\n return _.reduce(object, (acc, v, k) => {\n if (v) acc[k] = v\n return acc\n }, {})\n}\n\nmain().catch(send)\n",
"metadata": {
"author": "Waylay",
"iconURL": "https://static.waylay.io/plugs/icons/create-event-for-salesforce.png",
"description": "Create Custom Object in SalesForce\nMake sure the SalesForce Channel is up and running: see https://docs.waylay.io/integrations/salesforce/\n\nAvailable properties\n<ul>\n<li>customType: the type of custom object to be created. <b>Mandatory</b></li>\n<li>assetID: the Salesforce identifier for the asset. <b>Mandatory</b></li>\n<li>description: description string</li>\n</ul>",
"rawData": [],
"requiredProperties": [
"assetID",
"description",
"name",
"accountID"
],
"supportedStates": []
},
"dependencies": {
"jsforce": "1.10.0",
"pify": "5.0.0",
"@waylay/client": "2.20.0",
"lodash": "4.17.15"
}
}