This tutorial modifies an existing integration to demonstrate how you can create settings for your integration flows and then modify the logic of a flow based on those selections. The sample flow automates a common task: posting Salesforce opportunities to a Slack channel.
Later, we’ll be making choices available based on the value of records exported from Salesforce. Edit the export to view the SOQL query and the resulting fields.
Of interest for this exercise are the fields retrieved in the export, shown in the Preview data:
-
Name – a string with the customer’s name
-
Owner information – a list and a string with the account owner’s name
-
Amount – a numerical value for the opportunity
The new custom form will apply to the flow, in this example, as follows:
-
Open the flow, and click the Settings gear () button to edit it.
-
In the resulting Settings panel, expand the Custom section and click Launch form builder.
{ "fieldMap": { "minAmount": { "id": "minAmount", "name": "minAmount", "type": "text", "inputType": "number ", "defaultValue": "60000", "helpText": "Export is designed for at least $60,000 sales. Increase that amount here, if needed.", "label": "Extract opportunities larger than" }, "slackChannelMain": { "id": "slackChannelMain", "name": "slackChannelMain", "type": " checkbox ", "defaultValue": true, "label": "Send to default Slack channel (#general)" }, "slackChannelAlt": { "id": "slackChannelAlt", "name": "slackChannelAlt", "type": " radiogroup ", "label": "Pick an alternate channel", " options ": [ { "label": "#random", "value": "random" }, { "label": "#sales_opps", "value": "sales_opps" } ], " visibleWhen": [ { "field": "slackChannelMain", "is": [ false ] } ] } } }
-
This JSON adds three settings, the last of which is shown only when the checkbox for the default channel is deselected:
-
At this point, you can try modifying the form and clicking Test form to see how user-selected custom settings will be added to your flow – for example:
{ "minAmount": 80000, "slackChannelMain": false, "slackChannelAlt": "random" }
-
Save & close Form Builder, and save & close the flow’s settings.
The easiest way to exclude records is to filter them based on the value selected in the new setting Extract opportunities larger than ( settings.flow.minAmount).
-
In Flow Builder, click the Define options (+) button on the export and then click the Output filter () button to add a filter. The Define output filter panel opens.
-
For the field name (the left operand), select record.Amount in order to compare the exported opportunity dollar value.
-
Then, hover the mouse over the field name and click the Operand settings gear () button to its right:
-
Set the Operand type to Field.
-
Select Number for the Data type.
-
Click Save.
-
-
Select the operator: is greater than or equals.
-
Notice that your custom settings are available in both operands’ drop-down lists. For the second operand, select settings.flow.minAmount.
-
Also, click its Operand settings gear () button to the right:
-
Set the Operand type to Field.
-
Select Number for the Data type.
-
Click Save. (In practice, you may not be able to select the custom settings until after you save these operand settings.)
-
-
Save the filter to return to Flow Builder.
Now, when the flow runs, any Salesforce opportunities under the amount specified in the setting will be removed from the records sent downstream.
Before we continue, let’s examine this flow more closely:
-
Using JavaScript string concatenation, a message field is added to each Salesforce record inside a preSavePage hook. The resulting message sent to Slack then contains only the necessary values and minimal formatting.
function combineOppFields (options) { // Loop through each record options.data.forEach(function(r) { // Add a message field with Opportunity company, owner, & amount r.message = "*" + r.Name + "*\nAccount exec: " + r.Owner.Name + "; Amount: $" + commasGroup3(r.Amount); }) return { data: options.data, errors: options.errors, abort: false } }
-
The Slack import posts messages each time the flow runs:
-
The message and channel fields are mapped to their Slack equivalents:
We’ll have to add the channel field to this flow, so that it is not hard-coded and receives the value of the flow’s settings:
-
In Flow Builder, click the Define options (+) button on the import and then click the Hooks () button to add JavaScript code. The Hooks panel opens.
-
In the Pre map section, click the Create script (+) button. Name the new script and add the following function:
function setSlackChannel (options) { let channel = "general"; // Was 'Send to default Slack channel (#general)' unchecked? if (!options.settings.flow.slackChannelMain){ // Did the user select an alternate radio button for a channel? if (options.settings.flow.slackChannelAlt) { channel = options.settings.flow.slackChannelAlt; } } return options.data.map((d) => { if (d) { d.channel = channel } return { data: d } }) }
-
Click Save, and enter the Function name, setSlackChannel , into the Hooks panel as the Pre map entry point.
-
Save & close the import hooks.
First, run the flow without making any changes in the flow’s settings and verify that the opportunities are synced with Slack to the expected channel at the correct amounts:
Now, return to the settings:
-
Open the flow’s settings.
-
Expand the Custom section.
-
Change the amount to 80000 and the channel to random.
-
Save & close the settings.
-
Finally, run the flow again to verify that only amounts greater than or equal to $80,000 are now posted to #random:
Comments
Please sign in to leave a comment.