Comments? Questions? Get Involved? Join the Forum
An ECA (event-condition-action) rule is a specialized type of rule to conditionally run actions based on events. For Service ECA (SECA) rules the events are the various phases of executing a service, and these are triggered for all service calls.
Service ECAs are meant for triggering business processes and for extending the functionality of existing services that you don't want to, or can't, modify. Service ECAs should NOT generally be used for maintenance of data derived from other entities, Entity ECA rules are a much better tool for that.
Here is an example of an SECA rule from the AccountingInvoice.secas.xml file in Mantle Business Artifacts that calls a service to create invoices for orders when a shipment is packed:
<seca service="update#mantle.shipment.Shipment" when="post-service">
<condition><expression>statusChanged && statusId == 'ShipPacked' && !(oldStatusId in ['ShipShipped', 'ShipDelivered'])</expression></condition>
<actions>
<entity-find-one entity-name="mantle.shipment.Shipment" value-field="shipment"/>
<set field="shipmentTypeEnum" from="shipment.'ShipmentType#moqui.basic.Enumeration'"/>
<if condition="shipmentTypeEnum?.enumId == 'ShpTpOutgoing' || shipmentTypeEnum?.parentEnumId == 'ShpTpOutgoing'">
<service-call name="mantle.account.InvoiceServices.create#SalesShipmentInvoices" in-map="[shipmentId:shipmentId]"/>
</if>
</actions>
</seca>
The required attributes on the seca element are service with the service name, and when which is the phase within the service call. These two attributes together make up the event that triggers the SECA rule. There is also a run-on-error attribute which defaults to false and if set to true the SECA rule will be triggered even if there is an error in the service call.
The options for the when attribute include:
When the actions run the context will be whatever context the service was run in, plus the input parameters of the service for convenience in using them. If when is before the service itself is run there will be a context field called parameters with the input parameters Map in it that you can modify as needed in the ECA actions. If when is after the service itself the parameters field will contain the input parameters and a results field will contain the output parameters (results) that also may be modified.
The condition element is the same condition as used in XML Actions and may contain expression and compare elements, combined as needed with or, and, and not elements.
The actions element is the same as actions elements in service definitions, screens, forms, etc. It contains a XML Actions script. See the Overview of XML Actions section for more information.