Structure of a PaCE policy script
This section describes the structure of a PaCE policy script.
To debug the script, select the Debugger script icon . For more information, see Script Debugger API.
The following table lists the policy function parameters and how can they be used in your policy script.
| Variable Name | Description |
|---|---|
| logger | Logger is an object that the policy coder can use to log messages. The
log messages are stored in the sn_pace_execution_log table. You can review
these log messages for debugging, tracking, or monitoring purposes. The log messages can be
logged with one of the following levels:
When a policy is invoked through the API, you can specify the desired log level. For example:The format is as follows:
|
| current Record |
currentRecord is an object of the current version of the policy that
is executed when the policy is used. To view the currentRecord details,
navigate to the Versions tab on the Policy Home page and locate the
policy whose version state is set to Current. In the image below,
you can see that the current active version of the policy highlighted. It shows the
following details:
currentRecord object passed to the policy.This example shows how a policy developer can access the properties of the policy version record:
|
| document Record |
The
documentRecord
is used to map the policy to the relevant object (table and documentID) that is being validated. The documentRecord is a combination of the table_name and sysID. Based on the properties of the
object, the policy logic is used to manage and interact with the object being validated to determine the right decision.For example: In the DevOps Config environment, a policy can be mapped to the deployable. When the API is invoked, a query is initiated on the document (deployable) table and the Sys ID of the deployable.
This example shows how the documentRecord can be used in a policy
script: |
apiVars |
The apiVars is passed to the PaCE API when it is invoked. It includes all the API variables defined in the policy version. See <Defining Caller Inputs> section for details The Sample policy script shows how policies can be used to validate configuration data in the DevOps environment. In the sample script, the apiVars variable is defined as
where the specified snapshotId is mapped
to the corresponding snapshotId of the DevOps Config deployable being validated based on specified criteria.The policy developer can define logic in the policy script to use the apiVars values passed when the API is invoked to determine the decision. For example, the SnapshotID passed is used to identify key-values related to the specific snapshotID for a deployable passed in the documentRecord object. |
| configParams | Config Parameters are variables are passed when mapping the policy and includes all the Config Parameters variables defined for a specific version of the policy. The configParams variable is defined as follows in the Sample policy script.The policy developer can define the logic in the policy script to use the values passed at mapping to
determine the decision. For example, the dbPort number must be less than 30000, otherwise the policy is considered to be non_compliant. |
| recordRefs | Record references define queries to extract data from any ServiceNow® tables and use the data to configure the policy logic. There is an auto-completion function that can select the record reference in the Javascript editor. |
| dataCollectors | The data collectors function collects input process data from ServiceNow or an external data source to provide an output. |
| children Outputs |
Not supported in this version. |
| output This parameter is used to pass the output of the policy execution that includes the decision back to the calling service. It provides a decision related to this policy, with additional information such as errors, warnings, and result details. This example shows a sample output with compliant and non_compliant
decisions: |
|
| output. decision |
The decision property can be set to:
The decision is returned in a JSON format back to the calling service. 주: If a
value is not specified in the output.decision field in the script, when the
policy is executed, by default this field is set to compliant if
there are no failures. |
| output. results |
The |
| output. warnings |
The |
| output. failures |
The |
주: The following fields are automatically filled in when the PaCE policy script is executed. |
|
| output. name |
The name (current version) of the policy being executed. |
| output. state |
It indicates the state of the policy invocation.
|
- Auto-complete suggestions are available in the policy script editor for the
logger, callerInputandmappedInputparameter. - To view additional information for a parameter, enter the parameter name and select one of
the options as follows: