Articles in this section

Tutorial: Handling custom form decisions within a flow

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.

A. Examine the data structure

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.

360090419872-custom-forms-ex-1.png

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

B. Add a setting to the flow

The new custom form will apply to the flow, in this example, as follows:

  1. Open the flow, and click the Settings gear (settings_gear.svg) button to edit it.

    360090395951-custom-forms-ex-2.png
  2. In the resulting Settings panel, expand the Custom section and click Launch form builder.

    360090421232-custom-forms-ex-3.png
    {
      "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
              ]
            }
          ]
        }
      }
    }
  3. This JSON adds three settings, the last of which is shown only when the checkbox for the default channel is deselected:

    360090396891-Some_custom_form_attempts.png
  4. 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"
    }
  5. Save & close Form Builder, and save & close the flow’s settings.

C. Filter exported records based on the minAmount setting

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).

  1. In Flow Builder, click the Define options (+) button on the export and then click the Output filter (filterOut.svg) button to add a filter. The Define output filter panel opens.

    360090422812-custom-forms-filter-init.png
  2. For the field name (the left operand), select record.Amount in order to compare the exported opportunity dollar value.

  3. Then, hover the mouse over the field name and click the Operand settings gear (settings_gear.svg) button to its right:

    1. Set the Operand type to Field.

    2. Select Number for the Data type.

    3. Click Save.

    360083924712-custom-forms-filter-operand.png
  4. Select the operator: is greater than or equals.

  5. Notice that your custom settings are available in both operands’ drop-down lists. For the second operand, select settings.flow.minAmount.

  6. Also, click its Operand settings gear (settings_gear.svg) button to the right:

    1. Set the Operand type to Field.

    2. Select Number for the Data type.

    3. Click Save. (In practice, you may not be able to select the custom settings until after you save these operand settings.)

    360090423612-custom-forms-filter.png
  7. 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.

D. Set the Slack channel in a preSavePage hook

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:

360090424992-custom-forms-ex-import.png
  • The message and channel fields are mapped to their Slack equivalents:

360090425012-custom-forms-ex-map.png

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:

  1. In Flow Builder, click the Define options (+) button on the import and then click the Hooks (​​hook.svg​​) button to add JavaScript code. The Hooks panel opens.

  2. 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
        }
      })
    }
  3. Click Save, and enter the Function name, setSlackChannel , into the Hooks panel as the Pre map entry point.

    360090427952-custom-forms-ex-import_hooks.png
  4. Save & close the import hooks.

E. Try it out

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:

360090404231-custom-forms-ex-run-1.png

Now, return to the settings:

  1. Open the flow’s settings.

  2. Expand the Custom section.

  3. Change the amount to 80000 and the channel to random.

    360090430272-custom-forms-ex-run-1a.png
  4. Save & close the settings.

  5. Finally, run the flow again to verify that only amounts greater than or equal to $80,000 are now posted to #random:

    360090405471-custom-forms-ex-run-2.png
Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.