Quantcast
Channel: CRM Development forum
Viewing all articles
Browse latest Browse all 8223

Run a FetchXML query during pre-operation in a plug-in. Code inside.

$
0
0

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?


Viewing all articles
Browse latest Browse all 8223

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>