When an order is completed (status), we need to prevent users from adding order product either by clicking the + button, or by data import.
So I enabled the Before record added event of OrderProduct, and created the OrderProductInserting event sub-process trying to stop new orderproduct added if its relating order's status is completed.
I have tried successfully to stop orderproduct from adding as the code screenshots provided here. But what I don't know is how to get the order's status from within the method OrderProductInserting() so that I can call the ThrowInsertException() function to stop the order product added.
Here is an example of how to read OrderStatus Id inside the event process:
var order = Entity.GetTypedColumnValue<Guid>("OrderId");
var orderESQ =new EntitySchemaQuery(UserConnection.EntitySchemaManager, "Order");
orderESQ.UseAdminRights=true;
orderESQ.AddColumn("Id");
orderESQ.AddColumn("Status");
var entity = orderESQ.GetEntity(UserConnection, order);
var status = entity.GetColumnValue("StatusId").ToString();if(status =="{Completed OrderStatus Id}"){// DO Something}
Here is an example of how to read OrderStatus Id inside the event process:
var order = Entity.GetTypedColumnValue<Guid>("OrderId");
var orderESQ =new EntitySchemaQuery(UserConnection.EntitySchemaManager, "Order");
orderESQ.UseAdminRights=true;
orderESQ.AddColumn("Id");
orderESQ.AddColumn("Status");
var entity = orderESQ.GetEntity(UserConnection, order);
var status = entity.GetColumnValue("StatusId").ToString();if(status =="{Completed OrderStatus Id}"){// DO Something}