Adding A Workflow Type To Umbraco Forms
This builds on the "adding a type to the provider model" chapter
Add a new class to your project and have it inherit from Umbraco.Forms.Core.WorkflowType
, implement the class. For this sample we will focus on the execute method. This method process the current record (the data submitted by the form) and have the ability to change data and state.
Information available to the workflow
Record information
The Execute()
method gets a WorkflowExecutionContext
which has properties for the related Form
, Record
, and FormState
. This parameter contains all information related to the workflow.
The Record
contains all data and metadata submitted by the form. As shown in the example above, you can iterate over all RecordField
values in the form. You can also retrieve a specific record field by alias using the following method:
Having obtained a reference to a record field, the submitted value can be retrieved via:
The ValuesAsString
will JSON escape the result by default. If you do not want this escaping to occur, pass false
as the parameter.
If the field stores multiple values, they are delimited with a comma. In many cases, you can safely split on that delimiter to obtain the individual values. However, this can lead to issues if the prevalues being selected also contain commas. If that's a concern, the following extension method is available in Umbraco.Forms.Core.Extensions
to correctly parse the selected prevalues:
Form and state information
The Form
references the form the record is from and FormState
provides its state (submitted or approved).
Other context, such as the current HttpContext
, if needed can be passed as constructor parameters (for example: the HttpContext
can be accessed by injecting IHttpContextAccessor
).
Registering the workflow type
To use the new workflow type, you will need to register it as part of application startup.
Last updated