Skip to main content
Each script type has its own context and actions modules tailored to that automation scenario.

Overview

Request Review scripts run when an access request is assigned to a service user for review. The script can automatically approve, deny, or add comments to the request. This guide details the context and action modules you can use to get started, as well as the best practices and limitations when using OpalScript. For use case specific sample scripts, see our examples.

Quick start

The simplest script approves all requests:
A more practical script evaluates the request:

context Module

The context module provides read-only access to the request being reviewed.

Get the request object

context.get_request() returns the Request object being reviewed. None
Request
object
Contains information about the access request

actions Module

The actions module provides methods to take action on the request.

Approve a request

actions.approve([comment], [duration_minutes]) approves the request.
comment
string
Optional comment to add to the approval.
duration_minutes
int
Optional override for the access duration. Must be a positive integer. If different from the originally requested duration, a notice is automatically appended to the comment.

Deny a request

actions.deny(comment) denies a request. A comment is required to explain the denial.
comment
string
required
Comment explaining the denial.

Comment on a request

actions.comment(comment, [duration_minutes]) adds a comment without changing the request status. Useful for flagging requests or adding context for manual reviewers.
comment
string
required
Comment to add.
duration_minutes
int
Optional override for the access duration. Must be a positive integer. If different from the originally requested duration, a notice is automatically appended to the comment.

Pause execution

actions.pause(minutes) pauses script execution and resumes from the same point after the specified time. Any actions already taken before the pause are skipped on replay.
minutes
int
required
Number of minutes to pause. Must be between 1 and 1440 (24 hours).

Poll a condition

actions.poll(function, minutes, max_iterations) repeatedly calls function at the given interval until it returns True or the maximum iterations are reached. Returns True if the function succeeded, False if it ran out of iterations.
function
callable
required
A function that takes no arguments and returns a boolean. Execution resumes when it returns True or max_iterations is exhausted.
minutes
int
required
Interval between calls in minutes. Must be between 1 and 1440.
max_iterations
int
required
Maximum number of times to call the function. Must be between 1 and 50.

Objects

Request object

Returned by context.get_request() and contains information about the access request.

RequestedResource object

Represents a resource included in the request. Returned in the Request object.

RequestedGroup object

Represents a group included in the request. Returned in the Request object.

Custom fields

The custom_fields attribute is a dictionary containing values from the request template’s custom fields. The keys are field names, and values depend on the field type:

Constraints & limits

OpalScript enforces limits to ensure safe, predictable execution:

Unsupported operations

For security and reliability, OpalScript does not support:
  • Unrestricted network access: outbound HTTP is only available through the http module, and only to hosts on the egress allowlist
  • File I/O: Scripts cannot read or write files
  • Direct database access: All data access goes through provided modules
  • Import statements: All modules are pre-loaded
  • While loops: Use for loops with range() instead

Error handling

Scripts can fail due to various errors. Understanding common error types helps you write more robust scripts.

Syntax errors

None value errors

Type errors

Best practices

  1. Check for None before using optional attributes
  2. Use .get() with defaults when accessing dictionary values
  3. Keep scripts focused - do one thing well
  4. Test with edge cases - empty strings, None values, missing fields
Last modified on July 16, 2026