Using the JavaScript node in the <var class="keyword">
<div style="display: inline;">
RingCX
</div></var> Workflow Studio
=========================================================================================================================

The JavaScript node in <var class="keyword">
<div style="display: inline;">
RingCentral
</div></var>'s <var class="keyword">
<div style="display: inline;">
RingCX
</div></var> Workflow Studio lets you add custom actions to your call flows using JavaScript. You can use it to automate tasks such as checking a caller's account status, routing calls based on customer input, or sending a follow-up text message.

Although knowledge of JavaScript is required to use this node, there are built-in functions, specified in the [JavaScript functions](#javascript-functions "") table below, that simplify common tasks such as retrieving call data, modifying variables, and interacting with external systems.

Adding a JavaScript node
------------------------

To add a JavaScript node to your workflow:

* In the [<var class="keyword">
  <div style="display: inline;">
  Admin Portal
  </div></var>](https://service.ringcentral.com ""), click **Contact Center** , then select *Admin*. Sign in to [<var class="keyword">
  <div style="display: inline;">
  RingCX
  </div></var>](https://ringcx.ringcentral.com/ "") and click the **Admin** tile.
* In the left panel, click the **Categorization** icon, then click **Workflows**.
* Expand the workflow group, then click the **Workflow** you want to build.
* In the left panel, click **Workflow Studio**.
* Drag and drop the **JavaScript** node from the palette onto the background.
* Hover over the **JavaScript** node, then click **Edit**.
* Type a **Node ID** for the node.
* Type the JavaScript you want to execute in the space provided.
* Press CTRL+SPACE to bring up a dropdown menu that lists the [preexisting JavaScript functions](#javascript-functions "").

  ![Scripting Properties Node ID](https://assets.ringcentral.com/content/dam/xml-assets/doc_team/en_us/ringcentral/RingCX/Using-the-Scripting-node-in-the-RingCX-IVR-Studio/images/1-scripting-node.png)

* Click **OK**.

JavaScript functions
--------------------

Some JavaScript functions are available throughout a workflow with any trigger, and others are available only for IVR. IVR-specific functions can only be used with a **Start** trigger.

Note  
* All functions can use the *workflow*. prefix for both voice and digital channels with any trigger.
* For scripts created in IVR Studio before Workflow Studio was introduced, IVR-only functions can use the *ivr* . prefix and work with incoming voice calls on the **Start**trigger.
* The total execution time and complexity of the JavaScript node is limited to 5 seconds and 10000 bytecode operations. If both limits are exceeded, the Javascript node will exit and control will be returned to the next node in the workflow.
* Reading node results and storing data: The ivr.\* data functions in the table below (putData, getData, putReportField, getReportField) run on the IVR (Start trigger for voice interactions) engine. For reading the result of an executed node, workflow.nodes\['Node_ID'\].result works universally across all interactions and triggers and is recommended; ivr.getData('Node_ID') remains supported for existing IVR workflows. For temporary key/value storage, workflow.local is the equivalent of the ivr.putData/ivr.getData store.

|-------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------|
| **Function**                                                                                                                                                | **Description**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         | **Parameters**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | **Returns**                                                                                                                                                                                                                                                                                  | **Availability** |
| ivr.getContact()                                                                                                                                            | Locates the contact associated with the call in [Contact Management](https://support.ringcentral.com/article-v2/understanding-the-contact-info-panel-in-the-agent-interface.html?brand=RingCentral&product=RingCX&language=en_US "").                                                                                                                                                                                                                                                                                                                   |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  | A JSON object containing the response status and the contact details, if found. **Object properties:** **status**: The response code for the HTTP request. **message**: Includes an error message if the request has failed. **response.attributes**: An array of contact attributes.        |                  |
| ivr.getContact(Identifier: String, Value: String)                                                                                                           | Searches for a contact in [Contact Management](https://support.ringcentral.com/article-v2/understanding-the-contact-info-panel-in-the-agent-interface.html?brand=RingCentral&product=RingCX&language=en_US "") by a unique Identifier as specified in the request. If a contact is found, it will be associated with the interaction. If no contact is found, the previous contact association is removed. Note: getContact also supports making a call with no parameters and will return the current contact for the call if there is one associated. | **Identifier** : A string containing an identifier type (for example, Phone, Email, or ContactID) to be used in the contact search. **Value**: The string value of the identifier to be used in the contact search.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | A JSON object containing the response status and the contact details, if found. **Object properties**: **status**: The response code for the HTTP request. **message**: Includes an error message if the request has failed. **response.attributes**: An array of contact attributes.        | IVR              |
| ivr.createContact(CreateRequest: Object)                                                                                                                    | Creates a new contact in [Contact Management](https://support.ringcentral.com/article-v2/understanding-the-contact-info-panel-in-the-agent-interface.html?brand=RingCentral&product=RingCX&language=en_US "") that is automatically associated with the current interaction. Tip Use this function before connecting an agent so the contact appears at the beginning of the interaction.                                                                                                                                                               | **Create Request** : A JSON object containing the contact details to be created and associated with the current interaction. **Object properties**: **attributes**: An array of contact attributes.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | A JSON object containing the response status and the newly created contact, if successful. **Object properties**: **status**: The response code for the HTTP request. message: Includes an error message if the request has failed. **response.attributes**: An array of contact attributes. | IVR              |
| ivr.debug(Message: String) workflow.debug(Message: String)                                                                                                  | Adds a message to the debug log.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        | **Message**: A string containing the message to include in the log.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | Void                                                                                                                                                                                                                                                                                         | * IVR * Workflow |
| ivr.enqueueCall(ani: String, dnis: String, origDnis: String)                                                                                                | Takes an IVR call and makes it appear as if someone called another number on the platform.                                                                                                                                                                                                                                                                                                                                                                                                                                                              | **ANI** : Caller **DNIS**: Number you want to enqueue to. **origDnis**: Original number the caller dialed.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | Void                                                                                                                                                                                                                                                                                         | IVR              |
| ivr.error(Message: String) workflow.error(Message: String)                                                                                                  | Logs an error message to the debug log. Two debug emails will be sent: one for IVR and one for Workflow.                                                                                                                                                                                                                                                                                                                                                                                                                                                | **Message**: Error message to display.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           | Void                                                                                                                                                                                                                                                                                         | * IVR * Workflow |
| ivr.executeHttpNode(Node: Object)                                                                                                                           | Executes an HTTP node within the script block without transitioning to another workflow node. This allows API calls or external service requests to be made within the IVR script itself.                                                                                                                                                                                                                                                                                                                                                               | **Node** : The JSON object representing the HTTP node to execute. Note: The JSON for the node within the Workflow can be retrieved using the getJSONNodeByUid() method by providing the node UID.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                | A JSON object of the next node to be executed. Note: The result of the HTTP response JSON is added to the data map with the key of the HTTP node UID. This node can be retrieved using the getData() method.                                                                                 | IVR              |
| ivr.getAccountId()                                                                                                                                          | Returns the account ID associated with the current call.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                | None                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | A string containing the account ID.                                                                                                                                                                                                                                                          | IVR              |
| ivr.getAni()                                                                                                                                                | Returns the caller's phone number as an unformatted string.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | None                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | An unformatted string of the ANI. Note: For most accounts, this will be an E164-formatted number if the ANI is known. The IVR also supports a getAni(bool useE164) version, which returns an E164 number if useE164=true or a local number if useE164=false.                                 | IVR              |
| ivr.getConnection()                                                                                                                                         | Retrieves the ID of the connection assigned to be processed after the current node ends.                                                                                                                                                                                                                                                                                                                                                                                                                                                                | None                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | A string containing the ID of the connection set to be processed next.                                                                                                                                                                                                                       | IVR              |
| ivr.setContainerConnection(Connection: String) workflow.setContainerConnection(Connection: String)                                                          | Sets the path to follow when exiting the current container node.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        | **Connection**: The ID of a connection from the Container node.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  | Void                                                                                                                                                                                                                                                                                         | * IVR * Workflow |
| ivr.getContainerConnection() workflow.getContainerConnection()                                                                                              | Retrieves the ID of the connection assigned to be processed after the current container is complete.                                                                                                                                                                                                                                                                                                                                                                                                                                                    | None                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | A string containing the ID of the connection set to be processed after the current container is complete.                                                                                                                                                                                    | * IVR * Workflow |
| ivr.putData(Key: String, Value: String)                                                                                                                     | Adds data to a key/value store unique to the current call, discarded at the end of the call. Use the putReportField() function if you wish to add data that will persist after the call terminates and be available in reports.                                                                                                                                                                                                                                                                                                                         | **Key** : A name for the data point. **Value**: The value to associate with the key.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | Void                                                                                                                                                                                                                                                                                         | IVR              |
| ivr.getData(Key: String)                                                                                                                                    | Fetches data added to the key/value store by putData.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | **Key**: The name of the data point to retrieve.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 | A string containing the retrieved data.                                                                                                                                                                                                                                                      | IVR              |
| ivr.getDnis()                                                                                                                                               | Returns the number that the CCI platform received the call on.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          | None                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | An unformatted string of the DNIS.                                                                                                                                                                                                                                                           | IVR              |
| ivr.getRecordingUrl()                                                                                                                                       | Returns the URL where the call recording will be available after the call is ended and processed.                                                                                                                                                                                                                                                                                                                                                                                                                                                       | None                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | A string containing the URL where the call recording will be available.                                                                                                                                                                                                                      | IVR              |
| ivr.putReportField(Key: String, Value: String)                                                                                                              | Adds data to a key/value store that is unique to the current call and persists after the call completes.                                                                                                                                                                                                                                                                                                                                                                                                                                                | **Key** : The name for the data point. **Value**: The value to associate with the key.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           | Void                                                                                                                                                                                                                                                                                         | IVR              |
| ivr.getReportField(Key: String)                                                                                                                             | Fetches data added to the reportable key/value store by putReportField.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 | Key: The name of the data point to retrieve.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | A string containing the value associated with the key.                                                                                                                                                                                                                                       | IVR              |
| ivr.getDialDisposition()                                                                                                                                    | Retrieves the dial disposition from the customer call if available, primarily for Outbound RCX calls that have been transferred to an IVR.                                                                                                                                                                                                                                                                                                                                                                                                              | None                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | A string containing the dial disposition.                                                                                                                                                                                                                                                    | IVR              |
| ivr.getNodeByUid(UID: String)                                                                                                                               | Returns a node from the IVR with the provided UID in the form of a JSON object.                                                                                                                                                                                                                                                                                                                                                                                                                                                                         | **UID**: The UID string of the node to fetch.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | A JSON object representation of a node that can be used as a parameter for other API calls.                                                                                                                                                                                                  | IVR              |
| ivr.getUii()                                                                                                                                                | Gets the UII, a unique identifier of the current call in the CCI platform.                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | None                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | A string representing the call UII.                                                                                                                                                                                                                                                          | IVR              |
| ivr.goTo(UID: String)                                                                                                                                       | Used to jump to another IVR node within the current IVR.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                | **UID**: The UID of the IVR node to jump to.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | Void                                                                                                                                                                                                                                                                                         | IVR              |
| ivr.makeOutboundCall(Dial destination: String, Caller ID: String, Ring duration: Number, TT accept: Boolean, TT accept time: Number, Whisper audio: String) | Transfers the call to another destination. The IVR is disconnected when the outbound call is answered. This functions the same as the Route node.                                                                                                                                                                                                                                                                                                                                                                                                       | **Dial destination** : The number you want to transfer the call to. **Caller ID**: The caller ID you want to display to the called party. **Ring duration**: How long to ring the called party in seconds (the voicemail may pick up before this ends if you set it too high). **TT accept**: True or false (where true will require but not prompt the called party to press a digit on their phone to connect the call). **TT accept time**: How long in seconds to wait for the called party to accept the call using TT accept. **Whisper audio**: The name of the audio file you want to play to the destination prior to joining the outbound call to the IVR.                                                                                                                                                                             | Void                                                                                                                                                                                                                                                                                         | IVR              |
| ivr.playMusicOnHoldFile(FileName: String)                                                                                                                   | Plays a music audio file to the caller while the script continues. Use stopMusicOnHold() node to end.                                                                                                                                                                                                                                                                                                                                                                                                                                                   | **File name**: A string containing the name of the music audio file to be played while the script continues.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | Void                                                                                                                                                                                                                                                                                         | IVR              |
| ivr.setAutoTermInfo(autoTermInfo: Boolean)                                                                                                                  | Updates the call termination details in the reporting data. Adds the IVR as the termination party and sets the termination reason to the UID of the last node when the call is dropped.                                                                                                                                                                                                                                                                                                                                                                 | **True** : Enables automatic termination updates, assigning IVR as the termination party, and logging the last node's UID as the termination reason. The last node UID is also recorded in the IVR report under the variable name 'last_ivr_node'. **False**: Disables automatic termination updates, requiring manual assignment of the termination reason.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | Void                                                                                                                                                                                                                                                                                         | IVR              |
| ivr.getCallerName()                                                                                                                                         | Gets the caller name.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | None                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | String of caller name, or an empty string if unavailable.                                                                                                                                                                                                                                    | IVR              |
| ivr.setCallerName(String: String)                                                                                                                           | Sets the caller name for the call, overrides CNAM caller name resolution, and presents it to the agent on an inbound call or interaction.                                                                                                                                                                                                                                                                                                                                                                                                               | **Caller name**: A string with the caller name.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  | Void                                                                                                                                                                                                                                                                                         | IVR              |
| ivr.setConnection(Connection: String)                                                                                                                       | Sets the name of the connection to the next node processed when the current script ends.                                                                                                                                                                                                                                                                                                                                                                                                                                                                | **Connection**: The ID of a connection from the current JavaScript node.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         | Void                                                                                                                                                                                                                                                                                         | * IVR * Workflow |
| ivr.formatDate(Date: Object)                                                                                                                                | Returns the string representation of the given date object in the configured date format. The format can be set with the setDateFormat function.                                                                                                                                                                                                                                                                                                                                                                                                        | **Date**: The date to format.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | A formatted string representation of the provided date.                                                                                                                                                                                                                                      | * IVR * Workflow |
| ivr.setDateFormat(Format: String)                                                                                                                           | Sets the date format used by the formatDate function.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | **Format**: The format string to apply. Supports formats defined by the java.time.formatDateTimeFormatter class.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 | Void                                                                                                                                                                                                                                                                                         | * IVR * Workflow |
| ivr.setDTMFHandler(Node: Object)                                                                                                                            | Defines a node that is to be executed when DTMF digits are retrieved.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | **Node**: JSON object of the target node that the DTMF will trigger. This can be a node in the current IVR retrieved using the response of getNodeByUid.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         | Void                                                                                                                                                                                                                                                                                         | IVR              |
| ivr.setEarlyHangupMessage(Message: String)                                                                                                                  | Sets an audio file to be played if the call is transferred to another party, but the caller has disconnected before the transferred party answers.                                                                                                                                                                                                                                                                                                                                                                                                      | **Message**: A string containing the name of an audio file to play if the call is answered after the calling party has disconnected.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | Void                                                                                                                                                                                                                                                                                         | IVR              |
| ivr.setHangupHandler(Node: Object)                                                                                                                          | Define a node that is to be executed when the call is ended and a Hangup event is generated.                                                                                                                                                                                                                                                                                                                                                                                                                                                            | **Node** : JSON object of the target node that the Hangup will trigger. This can be a node in the current IVR retrieved using the response of getNodeByUid.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | Void                                                                                                                                                                                                                                                                                         | IVR              |
| ivr.setLanguage(Language: String)                                                                                                                           | Sets the current locale (\<language code\>-\<country code\>). This locale will be used for the duration of the IVR for the TextToSpeech, Speech Recognition, and PlayAudio audio functions. Supported locales are: * de-DE * en-AU * en-GB * en-US * es-ES * es-MX * es-US * es-419 * fr-FR * fr-CA * it-IT                                                                                                                                                                                                                                             | **Language**: A string containing the target language code and country code to use.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | Void                                                                                                                                                                                                                                                                                         | * IVR * Workflow |
| ivr.getSIPHeader(header name: String)                                                                                                                       | Pulls data from the SIP header of the call to be used in IVR Studio.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | **Header**: A string containing the name of the header that was embedded in the SIP call.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        | String of the data that is stored in the SIP header with the name used.                                                                                                                                                                                                                      | IVR              |
| ivr.setOutgoingSIPHeader(Header: String, Value: String)                                                                                                     | Adds a custom SIP header to the invite for an outgoing transfer executed from the Workflow. This allows additional call-related metadata to be passed to external systems.                                                                                                                                                                                                                                                                                                                                                                              | **Header** : A string containing the name of the header to embed in the SIP call. **Value**: A string containing the value assigned to the SIP header.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           | Void                                                                                                                                                                                                                                                                                         | IVR              |
| ivr.removeOutgoingSIPHeader(Header: String)                                                                                                                 | Removes a previously set SIP header from outgoing calls.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                | **Header**: A string containing the name of the header to be removed.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            | Void                                                                                                                                                                                                                                                                                         | IVR              |
| ivr.setTermInfo(Party: String, Reason: String)                                                                                                              | Sets termination information on the caller session. This will be reflected in the reporting data after the session is disconnected.                                                                                                                                                                                                                                                                                                                                                                                                                     | **Party** : Terminating party to set. **Reason**: Terminating reason to set.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | Void                                                                                                                                                                                                                                                                                         | IVR              |
| ivr.setTTAcceptList(TTAcceptList: String)                                                                                                                   | Sets the DTMF (Touch-Tone) digits that the IVR can accept if Touch-Tone (TT) input is enabled and an add session is triggered.                                                                                                                                                                                                                                                                                                                                                                                                                          | **TT accept list:** A string containing the DTMF digits the IVR can accept. **TT accept list**: A string containing TT accept digits.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            | Void                                                                                                                                                                                                                                                                                         | IVR              |
| ivr.setIvrTermInfo(Party: String, Reason: String)                                                                                                           | Sets termination information on the IVR session.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        | **Party** : Terminating party to set. **Reason**: Terminating reason to set.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | Void                                                                                                                                                                                                                                                                                         | IVR              |
| ivr.stopMusicOnHold()                                                                                                                                       | Stops the hold music.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | None                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | Void                                                                                                                                                                                                                                                                                         | IVR              |
| ivr.terminateCallSession(sessionId: String)                                                                                                                 | Terminates a particular session of a conferenced call.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  | **Session ID**: A string containing the session ID of the call session to be terminated.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         | Void                                                                                                                                                                                                                                                                                         | IVR              |
| ivr.waitForSilence(SilenceDuration Integer, MaxWaitTime Integer)                                                                                            | Waits and listens for a specified amount of silence. Once it detects silence for that duration, or if the maxWaitTime has been reached, the function ends, and the script can continue.                                                                                                                                                                                                                                                                                                                                                                 | **Silence Duration** : The number of seconds of silence to wait. **Max Wait Time**: The maximum amount of time that the IVR will listen for silence.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | Void                                                                                                                                                                                                                                                                                         | IVR              |
| ivr.sleep(Milliseconds: Number) workflow.sleep(Milliseconds: Number)                                                                                        | Pauses execution for the specified number of milliseconds. **Max**: 1 second **Limitation**: a JS node only allows one sleep attempt.                                                                                                                                                                                                                                                                                                                                                                                                                   | **Milliseconds**: Duration to sleep.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | Void                                                                                                                                                                                                                                                                                         | * IVR * Workflow |
| ivr.stringToXml(XML: String)                                                                                                                                | Attempts to parse the provided string as an XML document and returns the document.                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | **XML**: A string containing XML to parse.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | An org.w3c.dom.Document Java object.                                                                                                                                                                                                                                                         | IVR              |
| ivr.xmlToString(XML: org.w3c.dom.Document)                                                                                                                  | Returns the string representation of an org.w3c.dom.Document object.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | **XML**: The document object to process.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         | A string representation of the document.                                                                                                                                                                                                                                                     | IVR              |
| workflow.categories.setTo(categories: Array)                                                                                                                | Sets categories for an interaction. This will remove previously added categories and contain only the newly added ones.                                                                                                                                                                                                                                                                                                                                                                                                                                 | **Categories**: Array\<String\> containing categoryIds to be set.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                | Void                                                                                                                                                                                                                                                                                         | Workflow         |
| workflow.categories.add(categoryId: String, Array)                                                                                                          | Adds categories for an interaction.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | **CategoryId**: String or array of Strings containing the categoryIds to be added.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | Void                                                                                                                                                                                                                                                                                         | Workflow         |
| workflow.categories.remove(categoryId: String, Array)                                                                                                       | Removes one or more categories for an interaction.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | **CategoryId**: String or array of Strings containing the categoryIds to be removed.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | Void                                                                                                                                                                                                                                                                                         | Workflow         |
| workflow.categories.clearAll()                                                                                                                              | Removes all categories for an interaction.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | None                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | Void                                                                                                                                                                                                                                                                                         | Workflow         |
| workflow.categories.contains(categoryId: String, Array)                                                                                                     | Determines if one or more categories exist.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | **CategoryId**: A string or an array of categoryIds contained in the current interaction.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        | Boolean: true if at least one of the specified categories exists, false otherwise.                                                                                                                                                                                                           | Workflow         |
| workflow.base64.decodeAsString(base64: String)                                                                                                              | Decodes a base64 string to a string.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | **Data**: The base64 string to be decoded.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | The decoded data as an array of bytes.                                                                                                                                                                                                                                                       | Workflow         |
| workflow.base64.decodeUrlSafeAsString(urlSafeBase64: String)                                                                                                | Decodes URL-safe base64 to string.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | **Data**: The URL-safe base64 string to be decoded                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | The decoded data as an array of bytes.                                                                                                                                                                                                                                                       | Workflow         |
| workflow.base64.encode(data: String)                                                                                                                        | Encodes the input string to base64.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | Data: The data to be encoded as either a text string or an array of bytes.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | A base64 string encoding of the specified data.                                                                                                                                                                                                                                              | Workflow         |
| workflow.base64.encodeUrlSafe(data: String)                                                                                                                 | Encodes input to URL-safe base64.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | Data: The data to be encoded as either a text string or an array of bytes.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | A URL-safe base64 encoding of the specified data. This encoding differs from normal base64 in that some character substitution (per RFC 4648) occurs to make them safe to include in a URL.                                                                                                  | Workflow         |
| workflow.base64.fromUrlSafe(urlSafeBase64: String)                                                                                                          | URL-safe base64 to base64                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | **Data**: The data to be encoded as either a text string or an array of bytes.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | Returns a standard Base64-encoded string.                                                                                                                                                                                                                                                    | Workflow         |
| workflow.base64.toUrlSafe(base64: String)                                                                                                                   | base64 to URL-safe base64                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | **Data**: The data to be encoded as either a text string or an array of bytes.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | Returns a URL-safe Base64 string.                                                                                                                                                                                                                                                            | Workflow         |
| workflow.hmac.sign(data: String, key: String - Starting with "HMAC:", algorithm: String)                                                                    | Generates an HMAC signature for a given string using a key.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | **Data** : The data to be signed and encoded as a text string or an array of bytes. **Key**: The key to be used for signing, either directly as 'HMAC:\<base64-string\>' or by providing the credential ID. **Algorithm**: The hashing algorithm. Supported values include: "SHA-256" "SHA-384" "SHA-512"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        | The HMAC signature formatted as a base64 string.                                                                                                                                                                                                                                             | Workflow         |
| workflow.rsa.sign(data: String, key: String, algorithm: String )                                                                                            | Generates an RSA signature using the specified private key or credential ID.                                                                                                                                                                                                                                                                                                                                                                                                                                                                            | **Data** : The data to be signed, and encoded as a text string or an array of bytes. **Key**: The key to be used for signing, either directly as 'HMAC:\<base64-string\>' or by providing the credential ID. **Algorithm**: The hashing algorithm. Supported values include: "SHA-256" "SHA-384" "SHA-512"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | The HMAC signature formatted as a base64 string.                                                                                                                                                                                                                                             | Workflow         |
| workflow.rsa.verify(data: String, signature: String, key: String, algorithm: String)                                                                        | Verifies an RSA signature.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | **Data** : The original data that was signed. **Signature**: The signature to verify in base64 format. **Key**: The public key, either directly or by providing the credential ID, which must be PKCS#8 in PEM format. **Algorithm**: The hashing algorithm. Supported values include: "SHA-256" "SHA-384" "SHA-512"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | *true* if the signature is valid, *false* otherwise                                                                                                                                                                                                                                          | Workflow         |
| workflow.updateContext()                                                                                                                                    | Allows users to propagate the context at specific times within the workflow. Context in a workflow can be propagated to IVR, but IVR context cannot be propagated to the workflow.                                                                                                                                                                                                                                                                                                                                                                      | None                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | Void                                                                                                                                                                                                                                                                                         | Workflow         |
| convertTextToSpeech                                                                                                                                         | Prepares a text phrase to be spoken to the caller. The file name it returns can be used to play the speech in a [Play Audio](https://support.ringcentral.com/article-v2/Using-the-Play-Audio-node-in-the-RingCX-IVR-Studio.html?brand=RingCentral&product=RingCX&language=en_US "") node. Speech is generated by Microsoft Azure text-to-speech when the node plays the file. The file will be deleted when the workflow is completed.                                                                                                                  | **Voice** : The Azure voice to use, such as en-US-AvaMultilingualNeural. For available voices, go to Microsoft's [Azure voice list](https://learn.microsoft.com/en-us/azure/ai-services/speech-service/language-support?tabs=tts ""). Scripts written before RingCX moved to Azure can keep using Amazon Polly voice names, such as Joanna. RingCX replaces each one with an Azure voice, which can sound different from the original. Polly names are case-sensitive. To control exactly which voice plays, use an Azure voice name. If RingCX doesn't recognize the name, it uses the default voice for the call's language. **Text**: The text to be pronounced, as either plain text or SSML. The maximum length is 5,000 characters, and SSML tags count toward the limit. For more information, go to Using SSML with convertTextToSpeech. | A file name that a Play Audio node can play. Because the speech is generated only when the file plays, a conversion can fail after this function returns. For more information, go to [When text-to-speech fails](#text-to-speech-fails "").                                                 | IVR              |
| ivr.addMusicOnHoldFile(fileName: String)                                                                                                                    | Adds a music file to be played while the caller is on hold.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | **File Name**: A string containing the filename used to play a music audio file to the caller while the script continues.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        | Void                                                                                                                                                                                                                                                                                         | IVR              |
| ivr.clearMusicOnHoldFile(fileName: String)                                                                                                                  | Removes the music file that plays while the caller is on hold.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          | None                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | Void                                                                                                                                                                                                                                                                                         | IVR              |
| ivr.getCnam(e164_number:string)                                                                                                                             | Returns the CNAM caller name for the given number. For example, you may use the following: ivr.setCallerName(ivr.getCNAM(ivr.getANI())) If the number provided is invalid or the service providing the CNAM cannot be reached, an exception is raised.                                                                                                                                                                                                                                                                                                  | **164_number** : A string containing either a 10-digit NANPD number or an E.164-formatted number. Note: To retrieve the CNAM for the inbound callerId ID, you may use the return value from the getAni() method.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 | A string with the Caller name associated with the phone number.                                                                                                                                                                                                                              | IVR              |

Using SSML with convertTextToSpeech
-----------------------------------

The **Text** parameter of convertTextToSpeech accepts either plain text or Speech Synthesis Markup Language (SSML). If your text starts with a speak root element, RingCX sends it to Azure as SSML. RingCX passes your SSML to Azure as is. It doesn't validate the markup or adjust it for Azure. For supported elements and syntax, visit Microsoft's documentation:

* [SSML overview](https://learn.microsoft.com/en-us/azure/ai-services/speech-service/speech-synthesis-markup "")
* [SSML document structure](https://learn.microsoft.com/en-us/azure/ai-services/speech-service/speech-synthesis-markup-structure "")
* [Voice and sound: prosody, breaks, styles](https://learn.microsoft.com/en-us/azure/ai-services/speech-service/speech-synthesis-markup-voice "")
* [Pronunciation: say-as, phoneme, sub](https://learn.microsoft.com/en-us/azure/ai-services/speech-service/speech-synthesis-markup-pronunciation "")
* [Azure voice list by language](https://learn.microsoft.com/en-us/azure/ai-services/speech-service/language-support?tabs=tts "")

Note  
SSML support is provided as is. Which elements work, and how they sound, depends on Azure and on the voice you choose, and Microsoft can change this without notice. Test each prompt after you create or change it, and check it again from time to time.

### Choosing a voice in SSML

To use a specific voice, add an SSML voice element with an Azure voice name. Voice availability depends on Azure, so test the voice you choose before you use it in production. The voice element takes priority over the Voice parameter. If your SSML has no voice element, RingCX maps the **Voice** parameter to an Azure voice and uses that.

A name that isn't in the Azure format (language-REGION-NameNeural, for example en-US-AvaMultilingualNeural) is replaced with the default voice for the call's language. A correctly formatted name that doesn't exist in Azure isn't caught, and no audio plays. For more information, go to When text-to-speech fails.

### When SSML can't be used

If RingCX finds markup it can't send to Azure, such as malformed, unsafe, or unsupported tags, it removes the tags and speaks the remaining text without them.

### When text-to-speech fails

This behavior applies to plain text as well as SSML.

convertTextToSpeech doesn't create the audio right away. It returns a file reference, and the speech is generated only when a Play Audio node plays that file. If Azure can't generate the speech (for example because it rejects the SSML, the voice name doesn't exist, or the service is unavailable), the Play Audio node plays nothing and the workflow continues to the next node. convertTextToSpeech doesn't return an error, and your workflow can't detect the failure.

For prompts that callers must hear, such as menus or required notices, use recorded audio files instead. Test every text-to-speech prompt before you put it into production.

### Differences from Amazon Polly

SSML differs between text-to-speech vendors. SSML written for Amazon Polly, which RingCX used previously, can sound different on Azure, lose its effects, or produce no audio. Review your existing scripts and confirm they still sound the way you want.

For example, Polly treats prosody rate="100%" as normal speed, but Azure treats it as about twice as fast. On Azure, use +0% or default for normal speed, and -10% to slow the speech by 10%. Amazon-specific tags such as amazon:effect aren't supported.

JavaScript node connection properties
-------------------------------------

The JavaScript node has connector arrow properties that can be used for branching. These properties need to be configured.

To set up the connection properties, double-click the circle with the question mark on the connector arrow (A), then type a **Connection ID** (B) to determine if the workflow follows this path.

![Connection ID](https://assets.ringcentral.com/content/dam/xml-assets/doc_team/en_us/ringcentral/RingCX/Using-the-Scripting-node-in-the-RingCX-IVR-Studio/images/2-scripting-connection-properties.png)

The name on the connector arrow (A) is also used as the parameter in the **setConnection** function (B) to select the next node that the interaction will be sent to when the current JavaScript node ends.

![Scripting properties](https://assets.ringcentral.com/content/dam/xml-assets/doc_team/en_us/ringcentral/RingCX/Using-the-Scripting-node-in-the-RingCX-IVR-Studio/images/3-scripting-properties.png)

**Additional resources**  
[Using Workflow Studio in <var class="keyword">
<div style="display: inline;">
RingCX
</div></var>](https://support.ringcentral.com/article-v2/Intro-to-IVR-Studio-in-RingCX.html?brand=RingCentral&product=RingCX&language=en_US "")  
[Intro to workflows in <var class="keyword">
<div style="display: inline;">
RingCX
</div></var>](https://support.ringcentral.com/article-v2/Intro-to-IVR-Designer-in-RingCX.html?brand=RingCentral&product=RingCX&language=en_US "")  
[Intro to workflow triggers in <var class="keyword">
<div style="display: inline;">
RingCX
</div></var>](https://support.ringcentral.com/article-v2/Intro-to-workflow-triggers-in-RingCX.html?brand=RingCentral&product=RingCX&language=en_US "")  
[What nodes can do in <var class="keyword">
<div style="display: inline;">
RingCX
</div></var> IVR Studio](https://support.ringcentral.com/article-v2/What-nodes-can-do-in-RingCX-IVR-Studio-.html?brand=RingCentral&product=RingCX&language=en_US "")  
[Creating a workflow in <var class="keyword">
<div style="display: inline;">
RingCX
</div></var>](https://support.ringcentral.com/article-v2/Creating-an-IVR-in-RingCX.html?brand=RingCentral&product=RingCX&language=en_US "")