Variable insertion examples

Variable insertion examples

CE.png

This section provides practical examples of how to use variable insertion in common functions such as Email notification, HTTP client, and Database. Use these as starting points and adapt them to your own streams. More detailed, scenario-based examples using the https://infozone.atlassian.net/wiki/spaces/DAZ/pages/750813446 and https://infozone.atlassian.net/wiki/spaces/DAZ/pages/866549761 are provided in the child pages linked at the bottom of this page.

Example 1 - Email Notification: Sending the same message to different customers

This example shows how the https://infozone.atlassian.net/wiki/spaces/DAZ/pages/7862426 function uses variable insertion to insert the customer name into the message at runtime.

emailwriter_example.png
Workflow example

Script in the Script function

payload.customer_name = "Johnny"; payload.full_message = `Hello ${payload.customer_name}. You have received a new mail.`; await push(payload);

Configure the Email notification function so that the Message field uses payload.full_message.

Email-variable insertion.png
Variable insertion in the Email notification function configuration

When the stream runs, the recipient (Johnny) receives an email with the following content:

Hello Johnny. You have received a new mail.

Example 2 - HTTP Client: Building a URL from response data

This example shows how the https://infozone.atlassian.net/wiki/spaces/DAZ/pages/243531777 function uses variable insertion in the URL to call a Salesforce endpoint based on the instance_url that an earlier request stores in payload.sf_token.

"sf_token": { "access_token": "...", "instance_url": "https://digitalroute-dev-ed.my.salesforce.com", "id": "https://login.salesforce.com/id/00D7Q000006yDaMUAU/0057Q000004xQ4LQAU", "token_type": "Bearer", "issued_at": "1657697592923", "signature": "yRtGqYfqWx/oSx55De6UGsI0MXWDuUL5NKBXE5D2GnI=" }

To perform a POST request from the HTTP Client function, configure the URL as:

${payload.sf_token.instance_url}/services/data/v48.0/sobjects/blng_BillingRule_c

At runtime, the URL becomes:

https://digitalroute-dev-ed.my.salesforce.com/services/data/v48.0/sobjects/blng_BillingRule_c

Example 3 - Database function: Using a payload value in a SQL query

This example shows how the https://infozone.atlassian.net/wiki/spaces/DAZ/pages/7833182 function uses variable insertion to include a customer ID from the payload in a SQL query.

SQL query

SELECT username FROM account WHERE key = ${payload.customerId};

At runtime, ${payload.customerId} is replaced with the value from the incoming record.