How do I get the status of an order from its order product's OrderProductInserting event sub-process?

Hi community,

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.

Any code example will be very appreciated!

Andrew

Like 0

Like

2 comments
Best reply

Hello Andrew,

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
    		}

 

Hello Andrew,

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
    		}

 

Hi Dmytro, appreciate very much for the help. It works!

Show all comments