Scripting Best Practices
The information on this help page applies to both Studio and Desktop Studio.
To ensure your scripts are efficient, maintainable, and pass validation with a high health score, follow these industry best practices.
Variable and File Management
- All variable names should be meaningful.
- Use underscore characters ( _ ) instead of spaces in all file names.
- Use absolute paths when possible. They are clear and describe exactly where a file is located. Absolute paths are widely supported in Studio. However, some actions may support only relative paths. If you try an absolute path and it doesn't work but a relative path does, use the relative path. If you know both types work, it's best to use the absolute path.
- Always use the ASSIGN keyword when assigning a value to a variable in a SNIPPET action. When you use advanced search, you can quickly locate where a variable was created if you include the ASSIGN keyword. Without it, the search results show you every instance where the variable appears in your script.
- Address warnings early. Don't wait for a critical error from the script validator to optimize your script. Use the validator often and review warnings and info findings promptly to catch potential logic flaws before they impact production. For example, run the script validator after adding new logic or reconfiguring complex branches.
-
Always perform a final validation check before moving a script to a production environment to ensure no structural rules are violated.
Start and End Each Script Correctly
Every script must have a clear entry and exit point.
- Always include a BEGIN action. This establishes the starting point for the script's execution.
- Ensure every path includes a terminating action. Every logic branch should eventually lead to a proper termination point to prevent scripts from remaining active indefinitely. There are several terminating actions depending on the type of script.
Keep the Canvas Clean
Unconnected elements can clutter your logic and result in contact
The person interacting with an agent, IVR, or bot in your contact center. that get stuck.
- Remove orphaned actions, which are actions that aren't connected to the flow. These increase your Action Count and complexity score without adding value.
- Connect the Default branch condition for every action. This helps avoid issues when something unexpected happens and the script can't take any of the other branches. For actions that have it, relying on the onError branch condition may not be enough. There could be situations that occur that aren't errors and aren't handled by the other branch conditions. If you don't have a Default branch connected and something happens that's not covered by the other branches, the script and the contact get stuck at that point in the script.
- Connect all branches when using decision actions like IF or CASE , ensure every output branch is connected to a destination. Unwired branches can cause the script to fail if the logic hits a branch with no path.
- Change the Add caption property of each action to uniquely identify it and what it does in the script. This makes it easier to read and understand the flow of a script. Additionally, the captions of some labels appear in reports, such as the IVR Press Path report. Having unique names makes the reports more useful.
Manage Script Complexity
High complexity scores from the script validator can indicate a script that is difficult to troubleshoot or maintain.
- Modularize large scripts. Use the RUBSUB action to break your script into smaller, functional sub-scripts. This is particularly helpful for scripts that the script validator categorizes as Very Complex.
- Monitor dependency depth to avoid excessively long chains of actions. If your logic is too deep, look for ways to streamline the flow or use sub-scripts to flatten the architecture.
- Limit branch complexity. Too many decision points in a single script can make the logic hard to follow. Aim for a clean, readable flow.
- Use the Note action and the Annotation action to add comments to your script. You can use them to explain the flow of the script, the script's purpose, and the reasoning behind the scripting logic. You can also add comments to Snippet code in Snippet action. using two forward slashes (//).
- Review property density. If an action requires an unusually high number of configured properties, verify that the action is being used correctly and isn't over-complicated. The way you configure individual actions impacts the overall performance of the script.
Security and Resource Management
Maintain good security and resource management practices in your scripts.
- Use Integration Hub to store passwords, secrets, and other information that should not be included in the script itself. Integration Hub can also be used for some API calls.
- Make API calls using the RESTAPI action or Use Integration Hub, or using one of the other supported methods.
- Understand the limitations and recommendations for working with custom code in a SNIPPET action.
- Understand the impact that working with files in your scripts can have on your NiCE CXone system.