---
title: Script Libraries
slug: script-libraries
icon: {"faIcon":"fa-solid fa-book-open"}
docTags: 
createdAt: 2025-06-10T06:44:31.749Z
---

A Script library allows you to create reusable scripts to run across different server side capabilities of the platform including:

- [Inbound Messaging](docId\:zAh49ic1z3qdQpzkK0u9T)&#x20;
- [Record Generation](docId:91UoHxCs4DPgETX51VrId)&#x20;
- [System Controllers](docId:-pFjTclEM-zcu8ktP8zJW)&#x20;

A Script library also helps to abstract complexities that would otherwise be exposed onto the respective platform capabilities mentioned above.

# Creating a script library

| **Field name** | **Field type** | **Description**                                                                                                                                                                                                                                                                          | **Sample value**                                      |
| -------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------- |
| Name           | String         | Name of the script library                                                                                                                                                                                                                                                               | IncidentUtil                                          |
| Active         | Boolean        | Yes to activate the script library                                                                                                                                                                                                                                                       | Yes                                                   |
| Description    | Text           | Use to provide high level information on what the Script library is for.                                                                                                                                                                                                                 | Utility functions for the Incident management process |
| Script         | Script         | Classes and functions available within the Script library.<br />The name of the Script library needs to be the same as the one defined in the script. E.g. IncidentUtil<br />Just like any other server side scripting on the platform, Script library has access to Table API (Server)  | See below                                             |

### Example Script Library

```javascript
(function (undefined) {
    let IncidentUtil = function () {
        if (!(this instanceof IncidentUtil)) return new IncidentUtil();

        return this;
    };
    
    var log = Logger("IncidentUtil");

    /*
     * Function to find an Incident's related subtasks that are still opened
     * 
     * @Params:
     * _incRec - Table record of an Incident
     * 
     * @Return:
     * Array of incident task Table records
     */
    IncidentUtil.getIncidentOpenTasks = function (_incRec) {
        let retArr = [];

        if (_incRec) {
            _incRec.ParentIncidentForIncidentTasks.forEach(function(_taskRec) {
                if (!_taskRec.Closed()) {
                    retArr.push(_taskRec);
                }
            });
        }
        
        return retArr;
    }

    // Can add more functions in the same script library


    // Standard "require" vs "include" type construct
    if (typeof module !== "undefined" && module.exports) {
        module.exports = IncidentUtil;
    }

    return IncidentUtil;

})();
```

## Calling a Script library

If we are to call a function (called IncidentUtil.getIncidentOpenTasks) on the sample Script Library above on a Trigger for the Incident table, it will look like the following:

```javascript
// ... anything we want to do before calling the script library

let subTaskArr = IncidentUtil.getIncidentOpenTasks(current); // current is an Incident's Table record

// do what we want with subTaskArr
```

