---
title: Functions available in identity-related scripts
description: If you need to request specific resource versions, refer to REST API versioning.
component: pingoneaic
page_id: pingoneaic:idm-scripting:scripting-func-engine
canonical_url: https://docs.pingidentity.com/pingoneaic/idm-scripting/scripting-func-engine.html
keywords: ["Scripts", "Triggers"]
page_aliases: ["scripting-func-ref.adoc"]
section_ids:
  openidm_functions: openidm functions
  global-utility-functions: Global utility functions
---

# Functions available in identity-related scripts

|   |                                                                                                                              |
| - | ---------------------------------------------------------------------------------------------------------------------------- |
|   | If you need to request specific resource versions, refer to [REST API versioning](../idm-rest-api/rest-api-versioning.html). |

Identity-related functions (access to managed objects, system objects, and configuration objects) within Advanced Identity Cloud are accessible to scripts using the `openidm` object that's included in the top-level scope provided to each script.

Identity-related scripts can be created using [custom endpoints](script-custom-endpoints.html) or [script triggers](script-triggers.html).

## `openidm` functions

The script engine supports the following functions:

> **Collapse: openidm.create(resourceName, newResourceId, content, params, fields)**
>
> This function creates a new resource object.
>
> * Parameters
>
>   * resourceName
>
>     string
>
>     The container in which the object will be created, for example, `managed/realm-name_user`.
>
>   * newResourceId
>
>     string
>
>     The identifier of the object to be created, if the client is supplying the ID. If the server should generate the ID, pass null here.
>
>   * content
>
>     JSON object
>
>     The content of the object to be created.
>
>   * params
>
>     JSON object (optional)
>
>     Additional parameters that are passed to the create request.
>
>   * fields
>
>     JSON array (optional)
>
>     An array of the fields that should be returned in the result. The list of fields can include wild cards, such as `*` or `*_ref`. If no fields are specified, the entire new object is returned.
>
> * Returns
>
>   The created resource object.
>
> * Throws
>
>   An exception is thrown if the object could not be created.
>
> * Example
>
>   ```javascript
>   openidm.create("managed/realm-name_user", ID, JSON object);
>   ```

> **Collapse: openidm.patch(resourceName, rev, value, params, fields)**
>
> This function performs a partial modification of a managed or system object. Unlike the `update` function, only the modified attributes are provided, not the entire object.
>
> * Parameters
>
>   * resourceName
>
>     string
>
>     The full path to the object being updated, including the ID.
>
>   * rev
>
>     string
>
>     The revision of the object to be updated. Use `null` if the object is not subject to revision control, or if you want to skip the revision check and update the object, regardless of the revision.
>
>   * value
>
>     An array of one or more JSON objects
>
>     The value of the modifications to be applied to the object. The patch set includes the operation type, the field to be changed, and the new values. A PATCH request can `add`, `remove`, `replace`, or `increment` an attribute value.
>
>     A `remove` operation removes a property if the value of that property equals the specified value, or if no value is specified in the request. The following example `value` removes the `marital_status` property from the object, *if* the value of that property is `single`:
>
>     ```json
>     [
>         {
>             "operation": "remove",
>             "field": "marital_status",
>             "value": "single"
>         }
>     ]
>     ```
>
>     For fields whose value is an array, it's not necessary to know the position of the value in the array, as long as you specify the full object. If the full object is found in the array, that value is removed. The following example removes user adonnelly from bjensen's `reports`:
>
>     ```json
>     {
>         "operation": "remove",
>         "field": "/manager",
>         "value": {
>           "_ref": "managed/realm-name_user/adonnelly",
>           "_refResourceCollection": "managed/realm-name_user",
>           "_refResourceId": "adonnelly",
>           "_refProperties": {
>             "_id": "ed6620e4-98ba-410c-abc0-e06dc1be7aa7",
>             "_rev": "000000008815942b"
>           }
>         }
>     }
>     ```
>
>     If an invalid value is specified (that is a value that does not exist for that property in the current object) the patch request is silently ignored.
>
>     A `replace` operation replaces the entire field value. For array or multivalued relationship fields (such as `/roles`), this means the entire array is replaced, not just a single element. To swap a single element in an array, use a `remove` operation followed by an `add` operation.
>
> * params
>
>   JSON object (optional)
>
>   Additional parameters that are passed to the patch request.
>
> * fields
>
>   JSON array (optional)
>
>   An array of the fields that should be returned in the result. The list of fields can include wild cards, such as `*` or `*_ref`. If no fields are specified, the entire new object is returned.
>
> * Returns
>
>   The modified resource object.
>
> * Throws
>
>   An exception is thrown if the object couldn't be updated.
>
> * Examples
>
>   Patching an object to add a value to an array:
>
>   ```javascript
>   openidm.patch("managed/realm-name_role/" + role._id, null, [{"operation":"add", "field":"/members/-", "value": {"_ref":"managed/realm-name_user/" + user._id}}]);
>   ```
>
>   Patching an object to remove an existing property:
>
>   ```javascript
>   openidm.patch("managed/realm-name_user/" + user._id, null, [{"operation":"remove", "field":"marital_status", "value":"single"}]);
>   ```
>
>   Patching an object to remove a specific value from a multivalued relationship array:
>
>   ```javascript
>   openidm.patch("managed/realm-name_user/" + user._id, null, [{
>     "operation": "remove",
>     "field": "/roles",
>     "value": {
>       "_ref": "managed/realm-name_role/" + role._id,
>       "_refResourceCollection": "managed/realm-name_role",
>       "_refResourceId": role._id,
>       "_refProperties": {
>         "_id": "ef85ae74-6675-4f76-8bc3-19ac226cc703",
>         "_rev": "778e7955-cd0a-43c2-a714-7076d83fb710-132"
>       }
>     }
>   }]);
>   ```
>
>   Patching an object to replace a field value:
>
>   ```javascript
>   openidm.patch("managed/realm-name_user/" + user._id, null, [{"operation":"replace", "field":"/password", "value":"Passw0rd"}]);
>   ```
>
>   Patching an object to increment an integer value:
>
>   ```javascript
>   openidm.patch("managed/realm-name_user/" + user._id, null, [{"operation":"increment","field":"/age","value":1}]);
>   ```

> **Collapse: openidm.read(resourceName, params, fields)**
>
> This function reads and returns a resource object.
>
> * Parameters
>
>   * resourceName
>
>     string
>
>     The full path to the object to be read, including the ID.
>
>   * params
>
>     JSON object (optional)
>
>     The parameters that are passed to the read request. Generally, no additional parameters are passed to a read request, but this might differ, depending on the request. If you need to specify a list of `fields` as a third parameter, and you have no additional `params` to pass, you must pass `null` here. Otherwise, you simply omit both parameters.
>
>   * fields
>
>     JSON array (optional)
>
>     An array of the fields that should be returned in the result. The list of fields can include wild cards, such as `*` or `*_ref`. If no fields are specified, the entire object is returned.
>
> * Returns
>
>   The resource object, or `null` if not found.
>
> * Example
>
>   ```javascript
>   openidm.read("managed/realm-name_user/"+userId, null, ["*", "manager"]);
>   ```

> **Collapse: openidm.update(resourceName, rev, value, params, fields)**
>
> This function updates an entire resource object.
>
> * Parameters
>
>   * id
>
>     string
>
>     The complete path to the object to be updated, including its ID.
>
>   * rev
>
>     string
>
>     The revision of the object to be updated. Use `null` if the object isn't subject to revision control, or if you want to skip the revision check and update the object, regardless of the revision.
>
>   * value
>
>     object
>
>     The complete replacement object.
>
>   * params
>
>     JSON object (optional)
>
>     The parameters that are passed to the update request.
>
>   * fields
>
>     JSON array (optional)
>
>     An array of the fields that should be returned in the result. The list of fields can include wild cards, such as `*` or `*_ref`. If no fields are specified, the entire object is returned.
>
> * Returns
>
>   The modified resource object.
>
> * Throws
>
>   An exception is thrown if the object couldn't be updated.
>
> * Example
>
>   In this example, the managed user entry is read (with an `openidm.read`, the user entry that has been read is updated with a new description, and the entire updated object is replaced with the new value.
>
>   ```javascript
>   var user_read = openidm.read('managed/realm-name_user/' + source._id);
>   user_read['description'] = 'The entry has been updated';
>   openidm.update('managed/realm-name_user/' + source._id, null, user_read);
>   ```

> **Collapse: openidm.delete(resourceName, rev, params, fields)**
>
> This function deletes a resource object.
>
> * Parameters
>
>   * resourceName
>
>     string
>
>     The complete path to the to be deleted, including its ID.
>
>   * rev
>
>     string
>
>     The revision of the object to be deleted. Use `null` if the object isn't subject to revision control, or if you want to skip the revision check and delete the object, regardless of the revision.
>
>   * params
>
>     JSON object (optional)
>
>     The parameters that are passed to the delete request.
>
>   * fields
>
>     JSON array (optional)
>
>     An array of the fields that should be returned in the result. The list of fields can include wild cards, such as `*` or `*_ref`. If no fields are specified, the entire object is returned.
>
> * Returns
>
>   Returns the deleted object if successful.
>
> * Throws
>
>   An exception is thrown if the object couldn't be deleted.
>
> * Example
>
>   ```javascript
>   openidm.delete('managed/realm-name_user/'+ user._id, user._rev);
>   ```

> **Collapse: openidm.query(resourceName, params, fields)**
>
> This function performs a query on the specified resource object. Learn more in [Construct queries](../idm-objects/queries.html#constructing-queries).
>
> * Parameters
>
>   * resourceName
>
>     string
>
>     The resource object on which the query should be performed, for example, `"managed/realm-name_user"`, or `"system/ldap/account"`.
>
>   * params
>
>     JSON object
>
>     The parameters that are passed to the query (`_queryFilter`, or `_queryId`). Additional parameters passed to the query will differ, depending on the query.
>
>     Certain common parameters can be passed to the query to restrict the query results. The following sample query passes paging parameters and sort keys to the query.
>
>     ```javascript
>     reconAudit = openidm.query("audit/recon", {
>         "_queryFilter": queryFilter,
>         "_pageSize": limit,
>         "_pagedResultsOffset": offset,
>         "_pagedResultsCookie": string,
>         "_sortKeys": "-timestamp"
>     });
>     ```
>
>     Learn more about `_queryFilter` syntax in [Common filter expressions](../idm-objects/queries.html#query-filters) and paging in [Page query results](../idm-objects/queries.html#paging-query-results).
>
>   * fields
>
>     list
>
>     A list of the fields that should be returned in the result. The list of fields can include wild cards, such as `*` or `*_ref`. The following example returns only the `userName` and `_id` fields:
>
>     ```javascript
>     openidm.query("managed/realm-name_user", { "_queryFilter": "/userName sw \"user.1\""}, ["userName", "_id"]);
>     ```
>
>     This parameter is particularly useful in enabling you to return the response from a query without including intermediary code to massage it into the right format.
>
>     Fields are specified as JSON pointers.
>
> * Returns
>
>   The result of the query. A query result includes the following parameters:
>
>   * query-time-ms
>
>     (For JDBC repositories only) the time, in milliseconds, that IDM took to process the query.
>
>   * result
>
>     The list of entries retrieved by the query. The result includes the properties that were requested in the query.
>
>     The following example shows the result of a custom query that requests the ID, user name, and email address of all managed users in the repository.
>
>     ```json
>     {
>       "result": [
>         {
>           "_id": "9dce06d4-2fc1-4830-a92b-bd35c2f6bcbb",
>           "_rev": "00000000a059dc9f",
>           "userName": "bjensen",
>           "mail": "bjensen@example.com"
>         },
>         {
>           "_id": "42f8a60e-2019-4110-a10d-7231c3578e2b",
>           "_rev": "00000000d84ade1c",
>           "userName": "scarter",
>           "mail": "scarter@example.com"
>         }
>       ],
>       "resultCount": 2,
>       "pagedResultsCookie": null,
>       "totalPagedResultsPolicy": "NONE",
>       "totalPagedResults": -1,
>       "remainingPagedResults": -1
>     }
>     ```
>
> * Throws
>
>   An exception is thrown if the given query couldn't be processed.
>
> * Examples
>
>   The following sample query uses a `_queryFilter` to query the managed user repository:
>
>   ```javascript
>   openidm.query("managed/realm-name_user", {'_queryFilter': userIdPropertyName + ' eq "' + security.authenticationId  + '"'});
>   ```
>
>   The following sample query references the `for-userName` query, defined in the repository configuration, to query the managed user repository:
>
>   ```javascript
>   openidm.query("managed/realm-name_user", {"_queryId": "for-userName", "uid": request.additionalParameters.uid });
>   ```

> **Collapse: openidm.action(resource, actionName, content, params, fields)**
>
> This function performs an action on the specified resource object. The `resource` and `actionName` are required. All other parameters are optional.
>
> * Parameters
>
>   * resource
>
>     string
>
>     The resource that the function acts upon, for example, `managed/realm-name_user`.
>
>   * actionName
>
>     string
>
>     The action to execute. Actions are used to represent functionality that isn't covered by the standard methods for a resource (create, read, update, delete, patch, or query). In general, you shouldn't use the `openidm.action` function for create, read, update, patch, delete or query operations. Instead, use the corresponding function specific to the operation (for example, `openidm.create`).
>
>     Using the operation-specific functions lets you benefit from the well-defined [REST API](../idm-rest-api/preface.html), which follows the same pattern as all other standard resources in the system. Using the REST API enhances usability for your own API, and enforces the established patterns.
>
>     IDM-defined resources support a fixed set of actions. For user-defined resources (scriptable endpoints) you can implement whatever actions you require.
>
>   - Supported Actions Per Resource
>
>     The following list outlines the supported actions for each resource or endpoint. The actions listed here are also supported over the REST interface.
>
>     * Actions supported on the `authentication` endpoint (`authentication/*`)
>
>       reauthenticate
>
>     * Actions supported on the configuration resource (`config/`)
>
>       No action parameter applies.
>
>     * Actions supported on custom endpoints
>
>       Custom endpoints enable you to run arbitrary scripts through the REST URI, and are routed at `endpoint/name`, where name describes the purpose of the endpoint. Learn more about custom endpoints in [Create custom endpoints to launch scripts](script-custom-endpoints.html). You can implement whatever actions you require on a custom endpoint. IDM uses custom endpoints in its workflow implementation. Those endpoints and their actions are as follows:
>
>       `endpoint/getprocessforuser` - `create, complete`\
>       `endpoint/gettasksview` - `create, complete`
>
>     * Actions supported on the `external` endpoint
>
>       * `external/email` - `send`, for example:
>
>         ```javascript
>         var emailParams = {
>             "from" : "admin@example.com",
>             "to" : user.mail,
>             "subject" : "Your profile has been updated",
>             "type" : "text/plain",
>             "body" : "Details on your user profile have been successfully updated."
>         };
>         openidm.action("external/email", "send",  emailParams);
>         ```
>
>       * `external/email` - `sendTemplate`, for example:
>
>         ```javascript
>         var emailParams = {
>             "templateName" : "welcome",
>             "to" : user.mail,
>             "cc" : "ccUser1@example.com,ccUser2@example.com",
>             "bcc" : "bigBoss@example.com",
>             "object" : {
>                 "this": "value",
>                 "that": "another value"
>             }
>         };
>         openidm.action("external/email", "sendTemplate",  emailParams);
>         ```
>
>         |   |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
>         | - | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
>         |   | When sending an email template, there are two key parameters to understand:- **`templateName`**: This parameter identifies the template to send. Its value is the template's unique ID, which is generated from the template's original name and converted to camelCase. This ID is immutable, meaning it won't change even if you rename the template later.
>
>           You can find the template ID in the Advanced Identity Cloud admin console URL when editing the template. For example, the template ID for the Forgotten Username template is `forgottenUsername`:
>
>           ```none
>           https://<tenant-env-fqdn>/?realm=alpha#/email/templates/edit/forgottenUsername
>           ```
>
>         - **`object`**: This parameter passes dynamic data to the template. Email templates use [Handlebars expressions](https://handlebarsjs.com/guide/) to render data from the `object` parameter you provide.
>
>           To render the data from the example script, your template would use the following expressions:
>
>           * `{{object.this}}` resolves to `value`.
>
>           * `{{object.that}}` resolves to `another value`.Learn more in [Send email templates](../tenants/email-send.html#email-templates-send). |
>
>       * `external/rest` - `call`, for example:
>
>         ```javascript
>         openidm.action("external/rest", "call", params);
>         ```
>
>     * Actions supported on the `info` endpoint (`info/*`)
>
>       No action parameter applies.
>
>     * Actions supported on managed resources (`managed/*`)
>
>       patch, triggerSyncCheck
>
>     * Actions supported on the policy resource (`policy`)
>
>       validateObject, validateProperty
>
>       For example:
>
>       ```javascript
>       openidm.action("policy/" + fullResourcePath, "validateObject", request.content, { "external" : "true" });
>       ```
>
>     * Actions supported on the reconciliation resource (`recon`)
>
>       recon, reconById, cancel
>
>       For example:
>
>       ```javascript
>       openidm.action("recon/_id", "cancel", content, params);
>       ```
>
>       |   |                                                                            |
>       | - | -------------------------------------------------------------------------- |
>       |   | A *cancel* action requires the entire reconciliation resource path (\_id). |
>
>     * Actions supported on the repository (`repo`)
>
>       command
>
>       For example:
>
>       ```javascript
>       var r, command = {
>           "commandId": "purge-by-recon-number-of",
>           "numberOf": numOfRecons,
>           "includeMapping": includeMapping,
>           "excludeMapping": excludeMapping
>       };
>       r = openidm.action("repo/audit/recon", "command", {}, command);
>       ```
>
>     * Actions supported on the script resource (`script`)
>
>       eval
>
>       For example:
>
>       ```javascript
>       openidm.action("script", "eval", getConfig(scriptConfig), {});
>       ```
>
>     * Actions supported on the synchronization resource (`sync`)
>
>       getLinkedResources, notifyCreate, notifyDelete, notifyUpdate, performAction
>
>       For example:
>
>       ```javascript
>       openidm.action('sync', 'performAction', content, params);
>       ```
>
>     * Actions supported on system resources (`system/*`)
>
>       availableConnectors, createCoreConfig, createFullConfig, test, testConfig, liveSync, authenticate, script
>
>       For example:
>
>       ```javascript
>       openidm.action("system/ldap/account", "authenticate", {"username" : "bjensen", "password" : "Passw0rd"});
>       ```
>
>     * Actions supported on the task scanner resource (`taskscanner`)
>
>       execute, cancel
>
>     * Actions supported on the workflow resource (`workflow/*`)
>
>       On `workflow/processdefinition` create, complete
>
>       On `workflow/processinstance` create, complete
>
>       For example:
>
>       ```javascript
>       var params = {
>           "_key":"contractorOnboarding"
>       };
>       openidm.action('workflow/processinstance', 'create', params);
>       ```
>
>       On `workflow/taskinstance` claim, create, complete
>
>       For example:
>
>       ```javascript
>       var params = {
>           "userId":"manager1"
>       };
>       openidm.action('workflow/taskinstance/15', 'claim', params);
>       ```
>
>   - content
>
>     object
>
>     Content given to the action for processing.
>
>   - params
>
>     object (optional)
>
>     Additional parameters passed to the script. The `params` object must be a set of simple key-value pairs, and can't include complex values. The parameters must map directly to URL variables, which take the form `name1=val1&name2=val2&...`.
>
>   - fields
>
>     JSON array (optional)
>
>     An array of the fields that should be returned in the result. The list of fields can include wild cards, such as `*` or `*_ref`. If no fields are specified, the entire object is returned.
>
> * Returns
>
>   The result of the action may be `null`.
>
> * Throws
>
>   If the action can't be executed, an exception is thrown.

> **Collapse: openidm.encrypt(value, cipher, alias)**
>
> This function encrypts a value.
>
> * Parameters
>
>   * value
>
>     any
>
>     The value to be encrypted.
>
>   * cipher
>
>     string
>
>     The cipher with which to encrypt the value. Advanced Identity Cloud only supports AES with a key size of 128.
>
>   * alias
>
>     string
>
>     An encryption purpose defined in the secrets configuration *(tooltip: You can edit the secrets configuration over REST at the config/secrets endpoint.)*. The default is `idm.password.encryption`.
>
>     |   |                                                                                                                                                                                                                                                               |
>     | - | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
>     |   | The secrets configuration *(tooltip: You can edit the secrets configuration over REST at the config/secrets endpoint.)* contains mappings between keys and various functions. The keys reside in a keystore. To request a custom key, raise a support ticket. |
>
> * Returns
>
>   The value, encrypted with the specified cipher and key.
>
> * Throws
>
>   An exception is thrown if the object could not be encrypted.

> **Collapse: openidm.decrypt(value)**
>
> This function decrypts a value.
>
> * Parameters
>
>   * value
>
>     object
>
>     The value to be decrypted.
>
> * Returns
>
>   A deep copy of the value, with any encrypted value decrypted.
>
> * Throws
>
>   An exception is thrown if the object couldn't be decrypted for any reason. An error is thrown if the value is passed in as a string - it must be passed in an object.

> **Collapse: openidm.isEncrypted(object)**
>
> This function determines if a value is encrypted.
>
> * Parameters
>
>   * object to check
>
>     any
>
>     The object whose value should be checked to determine if it is encrypted.
>
> * Returns
>
>   Boolean, `true` if the value is encrypted, and `false` if it isn't encrypted.
>
> * Throws
>
>   An exception is thrown if the server is unable to detect whether the value is encrypted, for any reason.

> **Collapse: openidm.hash(value, algorithm, options)**
>
> This function calculates a value using a salted hash algorithm.
>
> Supported hashing algorithms and configuration properties
>
> The following list describes the algorithms and their configuration properties:
>
> * `BCRYPT`
>
>   * `cost`
>
>     Value between 4 and 31. The default is `13`.
>
> * `PBKDF2`
>
>   * `hashLength`
>
>     Byte-length of the generated hash. The default is `16`.
>
>   * `saltLength`
>
>     Byte-length of the salt value. The default is `16`.
>
>   * `iterations`
>
>     Number of cryptographic iterations. The default is `20000`.
>
>   * `hmac`
>
>     HMAC algorithm. The default is `SHA3-256`.
>
>     Supported values:
>
>     * `SHA-224`
>
>     * `SHA-256`
>
>     * `SHA-384`
>
>     * `SHA-512`
>
>     * `SHA3-224`
>
>     * `SHA3-256`
>
>     * `SHA3-384`
>
>     * `SHA3-512`
>
> * `SCRYPT`
>
>   * `hashLength`
>
>     Byte-length of the generated hash, must be greater than or equal to 8. The default is `16`.
>
>   * `saltLength`
>
>     Byte-length of the salt value. The default is `16`.
>
>   * `n`
>
>     CPU/Memory cost. Must be greater than 1, a power of 2, and less than *2^(128 \* r / 8)*. The default is `32768`.
>
>   * `p`
>
>     Parallelization. Must be a positive integer less than or equal to *Integer.MAX\_VALUE / (128 \* r \* 8)*. The default is `1`.
>
>   * `r`
>
>     Block size. Must be greater than or equal to 1. The default is `8`.
>
> * `SHA-256`
>
>   * `saltLength`
>
>     Byte-length of the salt value. The default is `16`.
>
>     |   |                              |
>     | - | ---------------------------- |
>     |   | This is the default hashing. |
>
> * `SHA-384`
>
>   * `saltLength`
>
>     Byte-length of the salt value. The default is `16`.
>
> * `SHA-512`
>
>   * `saltLength`
>
>     Byte-length of the salt value. The default is `16`.
>
> * Parameters
>
>   * value
>
>     any
>
>     The value to be hashed.
>
>   * algorithm
>
>     string (optional)
>
>     The hashing algorithm. Example: `SHA-512`.
>
>     If no algorithm is provided, a `null` value must be passed, and the algorithm defaults to SHA-256.
>
>   * options
>
>     For JavaScript, JSON object (optional)
>
>     Configuration properties for the selected algorithm.
>
> * Returns
>
>   The value, calculated with the specified hash algorithm.
>
> * Throws
>
>   An exception is thrown if the object couldn't be hashed for any reason.
>
> * Examples
>
>   * JavaScript
>
>     ```javascript
>     openidm.hash(\"dummy\", \"BCRYPT\", {\"cost\": 10})
>     ```

> **Collapse: openidm.isHashed(value)**
>
> This function detects whether a value has been calculated with a salted hash algorithm.
>
> * Parameters
>
>   * value
>
>     any
>
>     The value to be reviewed.
>
> * Returns
>
>   Boolean, `true` if the value is hashed, and `false` otherwise.
>
> * Throws
>
>   An exception is thrown if the server is unable to detect whether the value is hashed, for any reason.

> **Collapse: openidm.matches(string, value)**
>
> This function detects whether a string, when hashed, matches an existing hashed value.
>
> * Parameters
>
>   * string
>
>     any
>
>     A string to be hashed.
>
>   * value
>
>     any
>
>     The hashed value (as a `$crypto` object) to compare against the hash of the string.
>
>     |   |                                                                                                                                                                                                             |
>     | - | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
>     |   | To store an IDM hash value, don't enable hashing on a string attribute. The hash value is an object and not a string. Instead, use a custom attribute, such as a `custom_myHash` field, to store the value. |
>
> * Returns
>
>   Boolean, `true` if the hash of the string matches the hashed value, and `false` otherwise.
>
> * Throws
>
>   An exception is thrown if the string can't be hashed.
>
> * Example
>
>   JavaScript
>
>   ```javascript
>   (function () {
>       var body = request.content; (1)
>
>       if (request.method === 'create') {
>           // POST
>           // SHA256HashedPassword = openidm.hash(body.password, "SHA-256");
>           var hashedValue = {
>               "$crypto": {
>                   "value": {
>                       "algorithm": "SHA-256",
>                       "data": "QVjOMKdAifIxKC5y/bl4SXdlUx79EHLegucBF3SXEUP7LVKlXuluJH0J5y33a648"
>                   },
>                   "type": "salted-hash"
>               }
>           };
>           var SHA256HashedPassword = openidm.matches(body.password, hashedValue); (2)
>           return {
>               body: SHA256HashedPassword (2)
>           };
>       }
>   }());
>   ```
>
> |       |                                                                                                                                        |
> | ----- | -------------------------------------------------------------------------------------------------------------------------------------- |
> | **1** | Learn more about available fields for the request object in [Create custom endpoints to launch scripts](script-custom-endpoints.html). |
> | **2** | The `openidm.matches` function references the full `$crypto` object value instead of a hashed string.                                  |
>
> > **Collapse: Show example output**
> >
> > ```json
> > {
> >   "_id": "",
> >   "body": true  (1)
> > }
> > ```
> >
> > |       |                                                                         |
> > | ----- | ----------------------------------------------------------------------- |
> > | **1** | You must call the full `$crypto` object value to get a `true` response. |

## Global utility functions

These functions are available globally in the script execution context.

> **Collapse: btoa(stringToEncode)**
>
> Encodes a string in Base64. This is a global script binding that implements the canonical JavaScript `btoa` function.
>
> * Parameters
>
>   * stringToEncode
>
>     string
>
>     The string to Base64 encode. This string should consist of characters that can be represented by a single byte (Latin1 characters). For strings containing multi-byte characters, an error might occur or the output might be unexpected, as standard `btoa` is designed for binary strings.
>
> * Returns
>
>   An ASCII string representing the Base64 encoded version of `stringToEncode`.
>
> * Example
>
>   ```javascript
>   var originalString = "Hello World!";
>   var encodedString = btoa(originalString);
>   encodedString; (1)
>   ```
>
>   |       |                                                                        |
>   | ----- | ---------------------------------------------------------------------- |
>   | **1** | In this example, the returned `encodedString` is `"SGVsbG8gV29ybGQh"`. |

> **Collapse: atob(encodedString)**
>
> Decodes a Base64 encoded string. This is a global script binding that implements the canonical JavaScript `atob` function.
>
> * Parameters
>
>   * encodedString
>
>     string
>
>     The Base64 encoded string to be decoded.
>
> * Returns
>
>   An ASCII string representing the decoded version of `encodedString`.
>
> * Throws
>
>   An exception is typically thrown if the input `encodedString` isn't a valid Base64 string.
>
> * Example
>
>   ```javascript
>   var base64String = "SGVsbG8gV29ybGQh";
>   var decodedString = atob(base64String);
>   decodedString; (1)
>   ```
>
>   |       |                                                                    |
>   | ----- | ------------------------------------------------------------------ |
>   | **1** | In this example, the returned `decodedString` is `"Hello World!"`. |
