Hello,

I am working on a plugin for CRM on-prem v8. 

The plugin should be checking the quantities of the products which are added via another form.

So there is an Order form and the products are listed in another form, let's call it Order Lines. Order form does not have a direct field for use of EntityReference, so I am using the QueryExpression with the Order forms GUID, to get the Order Lines. In the Order Lines form, I have products with quantities and I need to check those quantities in another form that contains aggregated quantities of each product. 

I am calling this plugin on the "Update" message, PreOperation, from the Order form.

What is the best way to do it? Can I use the results from the QueryExpression together with the EntityReference?

Columnset columns:

{[sc_product, Microsoft.Xrm.Sdk.EntityReference]}

{[sc_location, Microsoft.Xrm.Sdk.EntityReference]}

Here is the code so far:

QueryExpression orderlineQuery = new QueryExpression { EntityName = "sc_salesorderline", ColumnSet = new ColumnSet(new string[] {"sc_product","sc_location","sc_quantity"}) };
                    orderlineQuery.Criteria = new FilterExpression();
                    orderlineQuery.Criteria.AddCondition("sc_salesorderno", ConditionOperator.Equal, new Guid(target.Attributes["sc_salesorderid"].ToString()));
                    orderlineQuery.Criteria.AddCondition("statuscode", ConditionOperator.Equal, "1");
                    var result = service.RetrieveMultiple(orderlineQuery);
                    trace.Trace("REsult " + result.ToString());
                    if (result.Entities.Count > 0)
                    {
                        foreach(var results in result.Entities)
                        {

                        }
                    }