Custom Code Snippets

The information on this help page applies to both Studio and Desktop Studio.

Some scripts require more complexity than Studio actions alone can provide. Studio allows you to add custom code to your scripts. This allows you to customize your scripts to meet your organization's needs.

Custom coding requires some scripting or programming knowledge. Studio uses a custom programming language called Snippet, developed for use in Studio. A complete technical reference guide is available in the online help so you can learn to use this language.

Key Facts About Snippets

  • Code snippets can help improve the organization and efficiency of your scripts. They increase your control over the processes that execute, as well as when and how they execute. You can create your own variables and objects and add programming logic using statements such as IF, FOR, FOREACH, and others.
  • Some products and features require snippets, but you can use them in your scripts even when they're not required.
  • When a product or feature requires code snippets, the online help provides detailed information about the snippets you need to include. Examples of scripts are provided to show how to use the code snippets in scripts. Additional scripting may be required to implement the products or features.
  • The Snippet scripting language is built on the .NET framework. It executes server-side and compiles into MSIL (Microsoft Intermediate Language) just as C# and Visual Basic .NET do.

Snippet Action

To add custom code to your scripts, you need a Snippet action. You can double-click this action to open an editor window where you can add your custom code. You can also debug the code in the editor window. You may need more than one Snippet action in your script. If you use multiple actions, update the Add Caption field of each one with a phrase that helps identify its purpose.

Placement of a Snippet action matters. If a Snippet assigns a value to a variable, it must be placed before the action that needs the value. On the other hand, if a Snippet contains decision-making code that acts based on a value passed to it, the Snippet must be placed after the action that provides the value.

Snippets Compared to Actions

Some of what you can do in snippets can also be done using Studio actions. For example, there are actions for IF and FOR statements. There's also the ASSIGN action, which you can use to create a custom variable and assign it a value. Using these actions is an acceptable way to add these capabilities to your script. However, using snippets is more efficient.

By placing code in snippets, your script is cleaner, more organized, and easier to navigate. This makes your job as a scripter easier and more efficient. If you make it a habit to always declare variables in snippets, then in the future if you need to locate a particular declaration, you have fewer places to look.

Add Custom Code to a Script

The Snippetaction allows you to add custom code to your scripts.

  1. In CXone Mpower, click the app selector and select Studio.
  2. On the Scripts page, locate and open your script.
  3. Add the Snippet action to your script and click Open Editor on the properties panel.
  4. Enter your code in the editor window. You can type the code in or copy and paste it from another source, such as this help site or another script.
  5. Click Apply to save your changes. The snippet editor closes. Reopen it to continue editing your code.