Entity view event rule
What are entity view event rules ?
Entity view event rules are pieces of code executed when events are triggered on the server application.
Writing rule code
In this article, we will focus on the available events. A detailed example is available in the quick start.
You can either write the C# code directly in the Neos Studio code editor or in Visual Studio (after the event rule has been saved once). See more about adding/editing server code. Example with a Saving event rule :
/// <inheritdoc/>
public Task OnSavingAsync(ISavingRuleArguments<IOrderView> args)
{
foreach (IOrderView order in args.CreatedAndModifiedItems)
{
order.Total = order.OrderDetails.Sum((od) => od.Subtotal);
}
return Task.CompletedTask;
}
The args
parameter content is detailed in the next section.
Rules properties
- Event rule : type of the event
- Business assembly : your code must be in a business code assembly associated with the reference item's module or in a child module. This will be the C# project the class will be created
Available rules
Several rules are available in an entity event view. This section is an exhaustive list of these rules.
Context
The context is shared between the Saving
/ Saved
events and Retrieving
/ Retrieved
events. A value added in the context during the Saving
event is available at the Saved
event level.
The context is also shared between the entity view Saving
/ Saved
events and the entity Saving
/ Saved
events. The order of triggering events is as follows:
- EntityView.Saving event
- Entity.Saving event
- Entity.Saved event
- EntityView.Saved event
Monitoring event rules execution
The execution of event rules can be tracked in the Backend monitoring
screen of the manager.