My case is: I want to execute a FetchXML query via a plugin on the pre-operation stage. I need to check if the existing record has certain fields filled. At the moment; I have this:
EntityCollection result = service.RetrieveMultiple(new FetchExpression(FetchXML)); Guid entityGUID = (Guid)entity.Id; foreach (var c in result.Entities) { if ((Guid)c.Attributes["accountid"] == entityGUID) { executeCondition = true; } } return executeCondition;
Which as you can see, taked in a FetchXML string, iterates through the collection, checks if there is a match with the current entity, and then if so, sets the executeCondtion to true.
The problem with this method is that during the Pre-Operation stage; the current record doesn't have a guid - it's not in the DB.
The other problem is that it is inefficient; I have over 10000 records, and so far it is just looping through all of them.
Does anyone know how I could achieve this?