Connectors

Functions Connector

The Functions connector lets you branch your PingOne DaVinci flow using logical conditions or based on the result of custom JavaScript code.

You can use the Functions connector to:

  • Compare the value of variables in your flow, such as A > B,

  • Perform calculations

  • Run custom JavaScript

For best practices to use custom code in your flows, see Using custom code safely.

Setup

Setting up the Functions connector

In DaVinci, add a Functions connection. For help, see Adding a connector.

This connector doesn’t have a configuration at the environment level. You configure it in your flow instead.

Using the connector in a flow

Comparing values

You can compare values using a variety of comparison capabilities, such as A == B, A != B, and A < B < C.

A node with the A == B capability cannot be branched from top:

A screen capture showing an incorrect example of branching from the top of an A == B node.

For example, we can check whether a user is eligible for a senior’s discount based on their age:

  1. In your flow, add the Functions connector and select the A >= B capability. Select the node that appears in your flow.

  2. In the Value A field, click {}, then select the attribute that holds the user’s current age.

  3. In the Value B field, enter 65.

    A screen capture of the user inserting variables into the value fields.
  4. After applying your changes, you can add a True branch from your node for seniors, and a False branch for those who aren’t.

Adding a custom function to your flow

You can make your flows more powerful and flexible by adding your own custom code. This capability lets you take inputs from your flow, work with them in JavaScript, and make the results available in your flow.

The JavaScript in a custom function runs on the server, not the client. These functions stay with your flow if you export it to another DaVinci environment.

For example, we want to know how long until a user turns 65 and gets a senior’s discount. We already know their age from earlier in the flow and that they’re younger than 65. Our code will subtract their current age from 65 and make the result available in the flow.

The following libraries are available in custom functions:

All code for custom functions must comply with JavaScript’s strict mode. For more information, see Strict Mode.

  1. In your flow, add the Functions connector and select the Custom Function capability.

  2. Select the node that appears in your flow.

  3. Make the variable with their current age available in your function:

    1. In the Variable Input List, click Add.

    2. In the Variable Name field, enter currentAge. Our code will call the variable by this name.

    3. In the Value field, click the input button and select the variable from your flow that you want as the value of currentAge in your function.

    4. In the Data Type list, select the type that best suits the value your variable holds.

    5. (Optional) To bring in more variables, click Add again.

      To remove an extra variable, click Edit, then click the remove button.

  4. In the Code field, enter your JavaScript custom code.

    To give yourself more room to work, click the Expand () icon. This lets you use your browser zoom to enlarge the code.

    Our code creates a variable called ageDelta that holds the difference between the user’s current age and 65:

    // How long until eligible for a senior’s discount?
    module.exports = a = async ({params}) => {
        Let ageDelta = 65 - params.currentAge
        return {'yearsUntilDiscount': ageDelta}
    }

    Our code returns a variable called yearsUntilDiscount.

  5. In the Output Schema field, capture the return variables from your code and make them available elsewhere in your flow.

    {
        "output": {
            "type": "object",
            "properties": {
                "yearsUntilDiscount": {
                    "type": "integer"
                }
            }
        }
    }

    Now, yearsUntilDiscount is available to use elsewhere in your flow.

Checking whether a variable has a value

When building a flow, it can be useful to check whether a variable contains a value. For example, testing whether the expected user ID or token has actually been provided earlier in the flow.

A screen capture of a short flow that branches based on whether a variable is empty.
  1. Check whether the variable is empty:

    1. In your flow, add a Functions connector with the A is Empty capability.

    2. In the Value A field, click {} and select the variable that you want to check.

    3. Enable Check undefined/null.

    4. In the Type list, select the type of data that the variable should contain.

      A screen capture of the A Is Empty capability configuration.
    5. Click Apply.

  2. Add a success path by following the A is Empty node using the Any Trigger False condition.

    The A is Empty capability returns "false" when the expected User ID, token, or other value is provided. As a result, the success path for your flow follows branches from the "false" result.

  3. Add an error message or failure path by following the A is Empty node using the All Triggers True condition.

Capabilities

A == B

If A equals B

Show details
Properties
leftValueA textField
rightValueB textField
type dropDown

A != B

If A is not equal to B

Show details
Properties
leftValueA textField
rightValueB textField
type dropDown

A < B

If A is less than B

Show details
Properties
leftValueA textField
rightValueB textField
type dropDown

A ⇐ B

If A is less than or equal to B

Show details
Properties
leftValueA textField
rightValueB textField
type dropDown

A > B

If A is greater than B

Show details
Properties
leftValueA textField
rightValueB textField
type dropDown

A >= B

If A is greater than or equal to B

Show details
Properties
leftValueA textField
rightValueB textField
type dropDown

B < A < C

If A is between B and C

Show details
Properties
leftValueA textField
rightValueB textField
rightValueC textField
type dropDown

B ⇐ A ⇐ C

If A is between B and C or equal to B or C

Show details
Properties
leftValueA textField
rightValueB textField
rightValueC textField
type dropDown

B ⇐ A < C

If A is between B and C or equal to B

Show details
Properties
leftValueA textField
rightValueB textField
rightValueC textField
type dropDown

B < A ⇐ C

If A is between B and C or equal to C

Show details
Properties
leftValueA textField
rightValueB textField
rightValueC textField
type dropDown

A is Empty

If A is Empty

Show details
Properties
leftValueA textField
Check undefined/null toggleSwitch

Check undefined/null

type dropDown

If Array A includes B

Show details
Properties
leftValueA textField
rightValueB textField
type dropDown
inputContains dropDown

If String A includes B

Show details
Properties
leftValueA textField
rightValueB textField

Custom Function

Show details
Properties
variableInputList variableInputList
code codeEditor

Follow example for code.

Default:

// Write your code here
// Supported language: Javascript
module.exports = a = async ({params}) => {
	console.log('params: ', params)
	return {'testVariable': params.testVariable}
}
outputSchema codeEditor

Follow example for JSON schema.

Default:

{
	"output": {
		"type": "object",
		"properties": {
			"testVariable": {
				"type": "string"
			}
		}
	}
}
Output Schema
output object
type object

Create a Hash

Show details
Properties
Hash Algorithm dropDown
Message for Hash textField
Input Schema
default object
message string required

Message to digest

digestAlgorithm string required

Algorithm, e.g. SHA256

Output Schema
output object
hash string

A == B (Multiple Conditions)

If A equals B or A equals to C …​

Show details
Properties
leftValueA textField
rightValueMultiple multipleTextFields
type dropDown