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
/
createCaseSalesForce.json
30 lines (30 loc) · 2.51 KB
/
createCaseSalesForce.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
26
27
28
29
30
{
"name": "createCaseSalesForce",
"version": "1.0.10",
"type": "actuator",
"script": "const jsforce = require('jsforce')\nconst pify = require('pify')\nconst Waylay = require('@waylay/client')\nconst _ = require('lodash')\n\nasync function main () {\n const caseObject = cleanObject({\n Subject: options.requiredProperties.Subject,\n Description: options.requiredProperties.Description,\n Status: options.requiredProperties.Status,\n Priority: options.requiredProperties.Priority,\n AssetId: options.requiredProperties.AssetId,\n AccountId: options.requiredProperties.AccountId,\n Reason: options.requiredProperties.Reason,\n OwnerId: options.requiredProperties.OwnerId,\n Product__c: options.requiredProperties.Product__c\n })\n\n const conn = await getSalesforceConnection()\n const SfCase = pify(conn.sobject('Case'))\n\n const res = await SfCase.create(caseObject)\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": "",
"iconURL": "https://static.waylay.io/plugs/icons/salesforce-create-case.png",
"description": "Add case in SalesForce, all fields are optional.\nIf accountId is not provided, it will be using the account\nof the person to who belongs the API token.\nIf AssetId it will take waylay resource as AssetId.",
"rawData": [],
"requiredProperties": [
"Subject",
"Status",
"Priority",
"AssetId",
"AccountId",
"Reason",
"OwnerId",
"Product__c",
"Description"
],
"supportedStates": []
},
"dependencies": {
"jsforce": "1.10.0",
"pify": "5.0.0",
"@waylay/client": "2.20.0",
"lodash": "4.17.15"
}
}