---
title: "Script libraries"
site: admin
version: 1.11
versions: "all"
url: https://docs-new.servicely.ai/admin/1.11/automation/script-libraries/
type: reference
application: platform
last_updated: 2026-10-18
commit: f37120b6b82b
---


A script library holds server functions that other scripts reuse, so the logic lives in one place. This page lists its fields and shows the template, for administrators and developers with the `administrator` role.

Script libraries are under **Administration → Business Logic → Script library**. Triggers, workflow activities, [inbound messages](page:messaging/inbound-messages), [record generators](page:automation/record-generators) and [Custom endpoints](page:api/rest/custom-endpoints) can all call them. See [Where scripts run](page:automation/scripting-overview).

## Script library fields

| Field | Type | Behaviour | Purpose |
| --- | --- | --- | --- |
| Name | Text | Required. Must match the name the script defines, for example `IncidentUtil`. | Other scripts call the library by this name. |
| Active | Yes or no | Default yes. | Only active libraries can be called. |
| Description | Text | Required. | Says what the library is for, for example "Utility functions for the Incident management process". |
| Script | Script | Required. Runs on the server and can use the [Table](page:api/scripting/table). | The functions the library provides. |

## Library template

This library defines one function, `getIncidentOpenTasks`, that returns an incident's open tasks. The lines that matter are:

- the outer function, which keeps the library's variables private
- the constructor named after the library, `IncidentUtil`
- the `module.exports` block and the final `return IncidentUtil;`, which make the library callable by name

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

    var log = Logger("IncidentUtil");

    /*
     * Returns the incident's tasks that are not closed.
     * @param _incRec - Table record of an incident
     * @return Array of incident task records
     */
    IncidentUtil.getIncidentOpenTasks = function (_incRec) {
        let retArr = [];
        if (_incRec) {
            _incRec.ParentIncidentForIncidentTasks.forEach(function (_taskRec) {
                if (!_taskRec.Closed()) {
                    retArr.push(_taskRec);
                }
            });
        }
        return retArr;
    };

    // Add more functions here

    if (typeof module !== "undefined" && module.exports) {
        module.exports = IncidentUtil;
    }

    return IncidentUtil;
})();
```

## Calling a library

A trigger on the Incident table calls the function by the library's name:

```javascript
let subTaskArr = IncidentUtil.getIncidentOpenTasks(current);
```

Inside a reclassification field map script, load the library first with `require`, for example `let WorkflowUtil = require("WorkflowUtil");`.

## Related

- [Where scripts run](page:automation/scripting-overview)
- [Triggers](page:automation/triggers)
- [Run a server script](page:automation/run-a-server-script)
- [Table](page:api/scripting/table)
