System-defined utilities
System-defined utilities are functions that expose activities to be used by a workflow creator. Invoking them as actions inside a workflow helps fulfill basic tasks without the need to create custom adapters. They come pre-packaged and are ready-to-use in any workflow definition.
Invoke a system utility in a workflow
To use a system utility function in a workflow execution, you must first define it under the functions
key in the workflow. Let’s take the NoOp
function as an example.
"functions": [
{
"name": "noop",
"metadata": {
"worker": "default"
},
"operation": "system.function.@latest.common.NoOp"
}
],
-
name
: A user-defined name for the utility function referred to inside the workflow definition. -
operation
: This is where you provide the utility function name (name of activity as with an adapter activity). -
worker
: Defining a worker is mandatory for all utility functions. Use thedefault
worker for this.
Make sure to define the worker
key with the value default
for each utility function.
"states": [
{
"name": "start",
"type": "callback",
"action": {
"name": "no operation",
"functionRef": {
"refName": "noop",
"arguments": {}
}
},
"eventRef": "cwm.forms.Check_applicant_age",
"metadata": {
"formData": "${ {user : .user} }",
"taskName": "Provide applicant age"
},
"timeouts": {
"eventTimeout": "PT15S",
"stateExecTimeout": "PT15M",
"actionExecTimeout": "PT15S"
},
"transition": "evaluate"
},
...
]
Note that the callback state requires the action
parameter to be stated. The name
and functionRef
keys need to have values provided even if no action is expected to happen during this state. Therefore, a mock action needs
to be provided. For this, you can use a CWM utility function, like noOp
, or any activity of your custom adapter, but keep in mind that the action needs to complete successfully for the workflow
to pass to another step.
See the descriptions of utilities below to learn more about them.
FailJob
system.function.@latest.common.FailJob
The FailJob
function allows a workflow creator to explicitly fail a workflow with a code and message when certain conditions are met,
which currently is not provided for in the Serverless workflow specification.
GetResourceType
system.function.@latest.resource.GetResourceType
GetResourceType
returns the Resource type for a given resource ID. You provide the resource ID using the resourceId
parameter inside the input
key under arguments
. You can provide it explicitly or use a variable that you will pass as the input data for the workflow.
Example:
"name": "begin",
"type": "operation",
"action": {
"name": "getResType",
"functionRef": {
"refName": "GetResourceType",
"arguments": {
"input": {
"resourceId": "${ .resID }"
}
}
}
},
NoOp
system.function.@latest.common.NoOp
NoOp
is used to perform a mock action during workflow execution. A great example of a use case for NoOp
is the Callback
state, which mandates that an action be invoked before the callback state waits for an event. It is perfectly valid for a
Callback
state to execute a mock action and just wait for an event which is capturing data from the user. The NoOp
function will help bypass the action and just wait for the defined event.
WaitUntil
system.function.@latest.common.WaitUntil
WaitUntil
introduces a pause in workflow execution based on a user-provided timestamp. The timestamp is the time until which the workflow
should wait provided in the RFC 3339 standard format using the timestamp
parameter inside arguments
.
Example:
"name": "begin",
"type": "operation",
"action": {
"name": "WaitUntil",
"functionRef": {
"refName": "WaitUntil",
"arguments": {
"timestamp": "2024-09-19T16:32:37+02:00"
}
}
},