Develop and manage OPUS Actions
Develop OPUS Actions with JavaScript to perform business logic when configured OPUS events occur. Use the execution context to work with event payloads, call APIs, send events, invoke agents, and manage action behavior during execution.
Use a clear and descriptive name that identifies the purpose of an OPUS Action. Use a consistent naming structure to make related OPUS Actions easier to identify and manage, especially when multiple OPUS Actions use the same event.
For example:
-
updateStatusOnInvoiceApproval
-
validateProductNameOnCreate
Keep the name concise. Use the field to provide additional information about the Action's purpose.
An OPUS Action uses a JavaScript function that receives the execution context through the ctx object.
A basic OPUS Action uses the following structure:
function execute(ctx) {
ctx.log.info('Processing Action');
return {
success: true,
response: '',
errorString: ''
};
}
execute
The action returns the following values:
-
success– Indicates whether the action succeeded. -
response– Contains response information. -
errorString– Contains error information when processing fails.
Use the ctx object to access runtime information and APIs available to the action.
Tip
-
Keep each OPUS Action focused on a specific business responsibility. Smaller actions are easier to test, troubleshoot, and reuse.
The ctx object provides runtime information and APIs to an OPUS Action.
Use the following properties to access event information and perform the required action logic.
| Property | Description |
|---|---|
ctx.log
|
Provides logging functions. |
ctx.api
|
Provides APIs available to the action. |
ctx.solutionId
|
Identifies the Solution associated with the event. |
ctx.processNetworkId
|
Identifies the Process Network associated with the event. |
ctx.agentIdentifier
|
Provides the Agent Binding context, when applicable. |
ctx.objectTypeName
|
Identifies the OPUS Object Type associated with the event. |
ctx.opusEventName
|
Identifies the OPUS Event that triggered the action. |
ctx.opusEventPayload
|
Provides the payload supplied by the event. |
ctx.envVars
|
Provides the configured environment variables. |
The event payload contains information supplied by the event that triggered the OPUS Action.
Access the event payload through:
ctx.opusEventPayload
The payload structure depends on the configured event:
-
A
POST_TRANSITIONpayload typically represents the object after the workflow transition. -
A
POST_OPERATIONpayload represents information returned by the completed operation.
Do not assume that every event provides the same payload structure. Inspect the payload before using specific fields.
For example:
function execute(ctx) {
ctx.log.debug(
JSON.stringify(ctx.opusEventPayload)
);
return {
success: true,
response: '',
errorString: ''
};
}
execute
Tip
-
Use logging during development to verify the payload supplied by the selected event.
Use ctx.api.gql.execute(...) to call supported GraphQL APIs from an OPUS Action.
Use GraphQL APIs to:
-
Add data in another OPUS app.
-
Edit related records.
-
Perform cross-app automation.
For example:
var gqlResponse = ctx.api.gql.execute(
ctx,
`mutation {
...
}`,
null,
null
);
The GraphQL API returns:
Check the returned success, response, and errorString values. The required GraphQL query or mutation depends on the app and business object.
Tip
-
Verify the Integration Principal permissions when troubleshooting a failed GraphQL call.
Some API calls might require routing or business-object context that differs from the event context.
Create header overrides using:
var headersOverride = ctx.api.newHeadersOverride();
Supported values might include:
-
processNetworkId
-
partnerNetworkNodeId
-
businessObject
-
baseObjectType
For example:
var headersOverride = ctx.api.newHeadersOverride();
headersOverride.processNetworkId = ctx.envVars.targetProcessNetwork;
headersOverride.businessObject = 'PurchaseOrder';
Use header overrides only when required by the downstream operation.
Use ctx.api.sendEvent(...) to send an event from an OPUS Action.
Use the following structure:
Use this method when downstream processing is event-driven rather than handled through a direct API call.
For example:
function execute(ctx) {
var response = ctx.api.sendEvent(
ctx,
'target-event',
'target-application',
JSON.stringify({
id: 'example-id'
}),
null
);
return {
success: response.success,
response: response.response,
errorString: response.errorString
};
}
execute
Verify the target event, target app, request payload, and required header overrides when configuring the call.
Use ctx.api.agent.invoke(...) to explicitly invoke the configured agent from an OPUS Action.
For example:
In this example, is the name of the Objective for the Agent.
Tip
-
An agent binding does not automatically invoke the agent. The JavaScript must explicitly call the Agent API.
Multiple OPUS Actions can use the same OPUS event.
For example, the same event can trigger:
-
One action that edits related data.
-
Another action that invokes an agent.
-
Another action that sends information to another app.
Each OPUS Action must independently match its configured binding. Configure multiple actions for the same event and binding.
Tip
-
Keep each OPUS Action focused on a specific business responsibility. This makes related actions easier to test and troubleshoot.
When multiple matching OPUS Actions use the same Event, OPUS executes them by binding level in the following order:
For example, consider an event with two matching Solution-bound Actions, one Process Network-bound Action, and one Agent-bound Action. The Solution Actions execute first. The Process Network Action executes next, followed by the Agent Action.
Actions that use the same binding execute in parallel. Their execution order is not guaranteed.
Tip
-
Do not design actions that depend on a specific execution order between actions using the same binding.
An unhandled error in an OPUS Action might prevent remaining actions associated with the same event from executing. Use appropriate error handling and logging when multiple actions depend on the same event.
For a event, the underlying business operation completes before the OPUS Action executes. If the action subsequently fails, the completed business operation remains successful. The action failure does not roll back the business operation.
Tips
-
Check downstream API responses for failures.
-
Use logging to diagnose action failures.
-
Test related actions that use the same event.
-
Do not rely on a specific execution order for actions using the same binding.


