Developers

Writing workflow nodes

Add your own workflow nodes as C# methods with OmniCore.Workflows.

Write your own workflow nodes in C# with the OmniCore.Workflows package. A node is a method marked [WorkflowNode]: its parameters are its inputs, and what it returns is its outputs. Building the project produces an .opl file, uploaded like a plugin.

A first package

xml
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <Version>1.0.0</Version>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="OmniCore.Workflows" Version="1.0.0" />
  </ItemGroup>
</Project>
csharp
using OmniCore.Workflows;

public static class Invoices
{
    public enum Band { Low, High }

    public sealed record Totals(decimal Net, decimal Vat, decimal Gross, Band Band);

    [WorkflowNode("acme.vat", "Add VAT", Description = "Works out VAT on a net amount.", Category = "Finance")]
    public static Totals AddVat(decimal net, [NodeInput(Description = "As a fraction: 0.15 is 15%.")] decimal rate = 0.15m)
        => new(net, net * rate, net * (1 + rate), net > 1000 ? Band.High : Band.Low);

    [WorkflowNode("acme.notify-buyer", "Notify buyer", Category = "Finance")]
    public static async Task NotifyBuyer(Guid supplier, [NodeInput(Multiline = true)] string message,
        INodeContext context, CancellationToken cancellationToken)
    {
        var entity = await context.GetAsync(supplier, cancellationToken);
        context.Log(quot;{entity?["name"]}: {message}");
    }
}

dotnet build makes the .opl. Upload it with OmniCore Admin → Plugins, occtl plugin install, or POST /api/plugins. The nodes then appear in the workflow designer under their category, marked with the package and version.

Nodes

A node is a public method of a public class: static, or on a class with a public parameterless constructor (one instance serves every run, so keep no per-run state in fields). It may be async.

AttributeOnSets
[WorkflowNode(id, name)]The methodId: unique across everything installed, prefixed with your package (acme.vat). Workflows store it, so keep it stable. Name, Description and Category (default General) for the designer.
[NodeInput]A parameterLabel, Description, Multiline.
[NodeOutput(name)]A property of the result, or [return: …]The output's name and description.
[NodeIgnore]A property of the resultLeaves it out of the outputs.

Inputs

Every parameter is an input, except an INodeContext and a CancellationToken, which the runtime passes. An input is required unless it has a default value or a nullable type.

Parameter typeDesigner typeSet as
stringTextText, with {{…}} placeholders
boolBooleantrue / false
int, longIntegerA number
double, decimalDecimalA number
DateTimeOffset, DateTimeDateTimeISO text (UTC if no offset)
GuidReferenceAn entity id
An enumChoiceOne of its names
JsonNode, JsonObject, JsonArrayJsonAny JSON; text in it can use {{…}}

Other types are refused when the package is uploaded, with a message naming the method. A value that can't be converted to the parameter's type fails the step, naming the input.

Outputs

  • A class or record: its public readable properties. Properties of the types above keep their type; others become JSON.
  • A single value: one output, result, or the name in [return: NodeOutput("…")].
  • Nothing (void, Task): no outputs.

Later nodes use them as {{nodeId.output}}, and conditions as nodeId.output > 1000. For the example above, a node vat gives {{vat.gross}}, and the condition vat.gross > 1000.

The context

INodeContext has everything a plugin's context has (get, query, create, update, add or remove perspectives, delete, with full access), plus:

Member
WorkflowThe workflow's name.
RunIdThe run's id.
NodeIdThe node's id in the workflow.
InputsWhat the run started with: the workflow's inputs, or the change or schedule that started it.
Log(message)Adds to the step's log in the run's history, and to the server log.

Writes are attributed to workflow:<name> and checked like any other.

Failing

Throw to fail the step, and the run. throw new NodeFailedException("No budget left") puts that message in the run's history; other exceptions show their type and message. A step has 60 seconds; then its cancellation token is cancelled and the run fails.

Packaging

The .opl is built by OmniCore.PlugIn's build step, which this package brings with it. A package can hold plugins and nodes together. An upload is refused if a node id is already taken (by a built-in node or another package), or if a node's signature can't be used. Replacing the package replaces its nodes; removing it leaves workflows that use them with problems, and they don't run until the nodes are back.