Evaluate Node

Add your custom JavaScript code to handle advanced business logic and computations

The Evaluate node allows you to run JavaScript code as part of a flow execution to handle complex flows that require advanced computations or data transformations.

The Configuration tab provides a script input box where you can add your own JavaScript code. The script output section allows you to conditionally branch the flow based on your script output.

180

Evaluate Node

Using Evaluate Node

1189

Evaluate Node

📘

Accessing Flow Variables in Evaluate Node

  • Custom Variables can be accessed by their names in the Evaluate node script. For example, a custom variable ‘Phone’ can be accessed as $(Phone).
  • Auto-generated (or Node Output variables) can be accessed as $(nodeid.variablename). For example, sms.timestamp is a variable in the SMS Start node and the Node ID for the Start node is always 2 (Node ID is available at the bottom left corner of the Node pop-up). Hence, sms.timestamp can be accessed in the script as $(n2.sms.timestamp). Note that you do not need to know the Node ID and variable format. Custom variables or Node Output variables can be accessed in the script by directly clicking the list of variables available on the right side of the Node pop-up. Click the variable name from the list to automatically populate the node variable with the correct formatting in the script.
  • The variables are case-sensitive.

Description of Interface elements:

S. NoElementDescription
1Configuration tabUse this tab to evaluate javascript.

Field descriptions:

Configure Script output
Specify a name for the script output in this field.

It appears in the Output Variables panel.

Branch Name
Once the script output is configured, then specify the branch name in this field.
2Transition Actions tabUse this tab to configure node on-enter/on-leave operations.
3Test buttonBoth the Configuration tab and the Transition Actions tab contain a Test button. Click the Test button on the Configuration tab to test the script output. Similarly, click the Test button on the Transition Actions tab to test the on-enter /on-leave operations that are configured.
4Input VariableClick this collapsible panel to view the list of all the available flow variables. You can search for a variable using the Search field. You can also add a variable to the flow variables list by clicking the Add new flow variable link at the bottom of the list.
5Output VariablesClick this collapsible panel to view the output variables.
6Node OutcomesClick this collapsible panel to view the list of possible node outcomes. You can also customize the node labels by clicking the Edit icon.
7Generate Code using AIEnable the toggle button to generate code using AI.
It is important to note that Bot builder application is mandatory for enabling the toggle to generate code using AI.
8Prompt textboxEnter the message which will be sent to the AI.
Example - Write a JavaScript for generating a 25-digit random string to use it as a Correlation ID.
9Script generated as output textboxThis is the script generated as output when the message added in the above Prompt textbox is sent to AI.
10Script editorEnter your script here. The script in the editor is executed during flow execution.

Evaluating a Script Output

You can evaluate the JavaScript in two steps: Configuring Script and Transition Actions.

Configuring the Script

As part of configuring the script, you need to first configure and then test it.

Here are the steps:

  1. Double click the Evaluate Node.
    The Evaluate screen appears. See the above image.
  2. Do the following on the Configuration tab:
    1. In the Input box, specify the Javascript, enter the Javascript, which you want to evaluate or generate code using AI.
    2. In the Script Output field, enter a name for the script output. It appears in the Output Variables in the panel.
    3. In the Branch Name field, enter a name for the branch.
      Note: Click the + Add New , if you want to configure more javascript.

Generate Code using AI

Generate sample JavaScript code tailored to your specific use case or requirements by providing a prompt. The resulting code is designed to be compatible with the JavaScript Engine utilized by Webex Connect.

Prerequisite: Code generation using AI requires Bot Builder App Tray. If Bot Builder is not enabled for your tenant, reach out to your account manager to get it enabled. For more information on Bot Builder, see here.

To generate code with AI:

  1. Double-click the Evaluate Node. The Evaluate screen appears.
  1. Enable the Generate Code using AI toggle button (field 7 in the above table)..
  2. Enter a prompt for the AI in the Prompt textbox (field 8 in the above table). Tip: To get the anticipated output from the Bot, the prompt message must be as descriptive as possible. Example - Write a JavaScript for generating a 25-digit random string to use it as a Correlation ID.
  3. Click Generate Code. Based on the prompt entered, the script is generated in the Output textbox (field 9 in the above table).
  4. Click Transfer Code to move the AI-generated script to your script editor (field 10 in the above table). The script will be transferred to the editor in a new line.
    Note: If the script output generated by the AI poses a security risk, you can report it.

📘

Note

If the script output generated by the AI poses a security risk, you can report it.

  1. Click Test. Make sure to test your script and verify that it is generating the desired output.

📘

Note

The Generate Code button is disabled after generating the code. It is enabled only when a new change is added to your previous prompt.

📘

Note

Each Bot Builder-enabled tenant is permitted a maximum of 1000 requests per month for generating scripts using AI. Once this quota is exhausted, it will automatically reset at the beginning of the next month. The quota of 1000 requests per month is applied across tenants and includes all groups and teams.

Report Output

To report the generated output:

  1. Click Report Output. A pop-up appears.
  2. Enter the feedback message and select the required checkbox under Report AI’s Output.
    Note: It is mandatory to enter one character and select one checkbox.
  3. Click Submit.

Pre-defined Functions

Webex Connect platform provides libraries that you can include in the Evaluate node. The libraries contain pre-defined functions that can be directly called instead of writing code for them. Use the following syntax at the beginning of the JavaScipt code to include libraries:

  • For single library - includeJs(LibraryName1)
  • For multiple libraries - includeJs(LibraryName1,LibraryName2,LibraryName3)

imi_general Library

The following table provides a list of functions available in this library:

Function NameNo. of ParametersParameter TypeOutput/ExampleNote
typeof1ANYReturns the type of the variable

IMI_GENERAL.typeof(<<variable_to_be_evaluated>>);
length1ANYReturns the length of the given object

IMI_GENERAL.length(<<variable_to_be_evaluated>>);
unicodeToString1Array or ObjectReturns the String from charCode

IMI_GENERAL.unicodeToString(<<variable_to_be_evaluated>>);
urlEncode1StringReturns the encoded URL

IMI_GENERAL.urlEncode(<<variable_to_be_evaluated>>);
urlDecode1StringReturns the decoded URL

IMI_GENERAL.urlDecode(<<variable_to_be_evaluated>>);
encodeURIComponent1StringReturns the complete encoded URL including the protocol

IMI_GENERAL.encodeURIComponent(<<variable_to_be_evaluated>>)
decodeURIComponent1StringReturns the complete decoded URL component

IMI_GENERAL.decodeURIComponent(<<variable_to_be_evaluated>>);
stringToUnicode2string, output_type ( output_type variable can accept 'string', 'array' and 'object')Returns the unicode of the provided string

IMI_GENERAL.stringToUnicode(<<variable_to_be_evaluated>>, '<<output_type>>');

imi_base64 Library

Function NameNo. of ParametersParameter TypeOutput/Example
encodeBase641StringReturns the encoded base64 string

var messageencode = base64encode(<<variable_to_be_evaluated>>);
decodeBase641StringReturns the decoded base64 string

var messagedecode = base64decode(<<variable_to_be_evaluated>>);

imi_strings Library

The following table provides a list of functions available in this library:

Function NameNo. of ParametersParameter TypeOutput/Example
length1ANYReturns the length of the variable

IMI_STRINGS.length(<<variable_to_be_evaluated>>);
concat2String and String
or
String and Number
Adds the provided input to the string

IMI_STRINGSs.concat(<<variable1_to_be_evaluated>>, <<variable2_to_be_evaluated>>);
lastIndexOf

The method name is case-sensitive
3 search_text (mandatory) - String
text (mandatory) - String
* start_pos (optional) - String; the start position from where the search should start within the string
Returns the position of the last occurrence of a specified value in a string. This method returns -1 if the value to search for never occurs.

Note: The string is searched from the end to the beginning, but returns the index starting at the beginning, at position 0.

IMI_STRINGS.lastIndexOf(<<search_text>>, <<text>>, <<start_pos>>);
indexOf3search_text (mandatory) - String

text (mandatory) - String

start_pos (optional) - String; the start position from where the search should start within the string
Returns the first occurrence position of the search_text within the actual text or returns -1 if not found

IMI_STRINGS.indexOf(<<search_text>>, <<text>>, <<start_pos>>);
search2 search_text (mandatory) - String or regular expression
text (mandatory) - String
Returns a number, representing the position of the first occurrence of the specified search value, or -1 if no match is found

IMI_STRINGS.search(<<search_text_or_regular_expression>>, <<text>>);
replace3 search_text (mandatory) - the value, or regular expression that needs to be replaced by the new value
newvalue (mandatory) - the value to replace the search value with
* text (mandatory) - String
Returns a new string, where the specified value(s) has been replaced by the new value.
If a normal string is provided, it will replace the first occurrence. For global use, use a regular expression instead.

IMI_STRINGS.replace(<<search_text_or_regular_expression>>, <<newvalue>>, <<text>>);
toUpperCase1StringReturns the upperCase format of the provided string

IMI_STRINGS.toUpperCase(<<variable_to_be_evaluated>>);
toLowerCase1StringReturns the lowerCase format of the provided string

IMI_STRINGS.toLowerCase(<<variable_to_be_evaluated>>);
trim1StringRemoves whitespace from both sides of a string

IMI_STRINGS.trim(<<variable_to_be_evaluated>>);
split2 text (mandatory) - String
separator (mandatory) - String
Converts the provided string to an array based on the provided separator

IMI_STRINGS.split(<<variable_to_be_evaluated>>, <<separator>>);
slice3 start (mandatory)- the position where to begin the extraction. The first character is at position 0
end(optional) - the position (up to, but not including) at which to end the extraction. If omitted, slice() selects all characters from the start position to the end of the string
* text (mandatory) - the actual text
Returns a string, representing the extracted part

IMI_STRINGS.slice(<<start>>, <<end>>, <<the_actual_text>>);
substring3 start (mandatory) - the position where to start the extraction. The first character is at index 0
text (mandatory) - the actual text
* end (optional) - the position (up to, but not including) at which to end the extraction. If omitted, it extracts the rest of the string
Returns a string containing the extracted characters

IMI_STRINGS.substring(<<text>>, <<start>>, <<end>>);
substr3 start (mandatory) - the position where to start the extraction. The first character is at index 0. If start is positive and greater than, or equal, to the length of the string, substr() returns an empty string. If start is negative, substr() uses it as a character index from the end of the string. If start is negative or larger than the length of the string, start is set to 0.
length (optional) - the number of characters to extract. If omitted, it extracts the rest of the string
* text (mandatory) - the actual text
Returns a string, containing the extracted part of the text. If length is 0 or negative, an empty string is returned

IMI_STRINGS.substr(<<start>>, <<length>>, <<text>>);

imi_array Library

The following table provides a list of functions available in this library:

Function NameNo. of ParametersParameter TypeOutput/Example
concat1args (mandatory) - an array of elementsReturns an array object, representing the joined ar

IMI_ARRAY.concat(<<Array_of_Elements>>);
indexOf3 array (mandatory) - the original array
item (mandatory) - the item to search for
* start (optional) - the position from where to start the search. Negative values will start at the given position counting from the end, and search to the end
Returns a number, representing the position of the specified item, otherwise -1

IMI_ARRAY.indexOf(<<Original_Array>>, <<Item_to_Search>>, <<optional_start_position>> );
isArray1object (mandatory)Returns true if the object is an array, otherwise it returns false

IMI_ARRAY.isArray(<<variable_that_need_to_tested>>);
join2 array (mandatory) - the original array
separator (optional) - the string value which is used as a separator between the array elements
Returns a string, representing the array values, separated by the specified separator

IMI_ARRAY.join(<<Array>>, <<Optional_Separator>>);
lastIndexOf3 array (mandatory) - the original array
item (mandatory) - the item to search for
* start (mandatory) - the position from which to start the search. Negative values will start at the given position counting from the end, and search to the beginning
Returns a number, representing the position of the specified item, otherwise -1

IMI_ARRAY.lastIndexOf(<<Original_Array>>, <<Item_to_Search>>, <<optional_start_position>> );
push2 array (mandatory) - the original array
items (mandatory) - an array of Items
Returns a number, representing the new length of the array. Note*: Add item at the end of the array

IMI_ARRAY.push(<<Original_Array>>, <<Array_of_Items>> );
unshift2 array (mandatory) - the original array
items (mandatory) - an array of items
Returns a number, representing the new length of the array. Note*: Add item at the beginning of the array

IMI_ARRAY.unshift(<<Original_Array>>, <<Array_of_Items>> );
reverse1array (mandatory) - the original arrayReturns an array, representing the array after it has been reversed

IMI_ARRAY.reverse(<<Original_Array>> );
splice4 array (mandatory) - the original array
index (mandatory) - an integer that specifies at what position to add/remove items. Use negative values to specify the position from the end of the array
howmany (optional) - the number of items to be removed. If set to 0, no items will be removed
items (mandatory) - an array of elements to be added to the original array
Adds/removes items to/from an array, and returns the removed item(s)

IMI_ARRAY.unshift(<<Original_Array>>, <<Index>>, <<Optional_howmany>>, <<Array_of_elements>> );
fill4 originalarray (mandatory) - array
value (mandatory) - the value to be filled in array
start (optional) - the position from where to start filling the value in the array
end (optional) - the position to stop filling the value in the provided originalarray
Returns the changed array

IMI_ARRAY.fill(<<Original_Array>>, <<value>>, <<Start>>, <<end>> );

Testing the Script

After configuring the script output, you need to test it to evaluate its function.

  1. Click Test button at the bottom.
    The Test Evaluate Script window appears.
  2. On the Test window:
    • In the Variable Name field, enter the variable. For example, age.
    • In the Value field, enter the value corresponding to the variable.
    • Click the Test button at the bottom to test it.
739

Test Window

  • Finally, click the Save button at the bottom.
    The script is evaluated.

Configuring Transition Actions

The Transition Actions tab in a node enables you to configure the On-enter and On-leave actions to capture logs when the flow is executed.

For information, see Transition Action.

FAQs

  1. Is the script generated by AI always secure?
    It is advisable to verify and test the script using the 'Test' option in the node before incorporating it into the flow. The script generated by AI is designed to be compatible with the JavaScript Engine employed by Webex Connect. However, it's important to acknowledge that a third-party tool is utilized for script generation.
  2. I have written a prompt to AI, but when I click on generate code, I receive TPS reached error? I have not exhausted my 1000 request per month quota.
    Access to TPS for code generation using AI is limited for each tenant. Please attempt the operation again. If the issue persists, kindly raise an operational ticket or contact your account manager for further assistance.