Microsoft Dynamics CRM 2011

Microsoft Dynamics CRM 2011

Saturday, June 9, 2018

CRM RetrieveMultiple QueryExpression to retrieve the top one last created record

In this article we see Step by step How to write a C# query Microsoft Dynamics CRM QueryExpression  to retrieve the top one last created record/modified record , in both CRM 2011 , CRM 2013 ,CRM 2015 and Microsoft Dynamics 365 .
We'll use the IOrganizationService RetrieveMultiple method with a FilterExpression and a ConditionExpression, to get only one record: the latest one created . We also check an attribute for null values .
Usually this C# code will be run from a Dynamics CRM Plugin.
Download the C# code from the following GitHub repository:


We'll see here in only 10 minutes how to write the CRM query , which will be shown this way , for example :
CRM RetrieveMultiple QueryExpression to retrieve the top one last created record



CRM RetrieveMultiple QueryExpression to retrieve the top one last created record/last modified record


First , you need to set which columns to retrieve. It is strongly recommended that you do not select all columns in an of the Microsoft Dynamics CRM SDK entity :
CRM RetrieveMultiple QueryExpression to retrieve the top one last created record



Next, we create the QueryExpression that will hold the query to be send to the OrganizationService , as follows :
CRM RetrieveMultiple QueryExpression to retrieve the top one last created record


There, we add an OrderExpression to sort the records acording to its "createdon" or "modifiedon" attribute.


Then, we cut the results to just the first result and circumscribe them to the first page:

CRM RetrieveMultiple QueryExpression to retrieve the top one last created record



Then, we can check some determined attribute to contain a value - with the not null ConditionOperator:

CRM RetrieveMultiple QueryExpression to retrieve the top one last created record



And include all conditions in a FilterExpression, into the Criteria:
CRM RetrieveMultiple QueryExpression to retrieve the top one last created record





The complete query will look something like this (this code has been tested , and works very well) :

CRM RetrieveMultiple QueryExpression to retrieve the top one last created record





The steps are as follows:
0) Set which columns to retrieve.
1) Create the QueryExpression
2) Add an OrderExpression
3) Check some determined attribute to contain a value using a ConditionOperator (optional)
4) Include all conditions inside  the Criteria as a FilterExpression
5) Send a RetrieveMultiple with the QueryExpression


Happy CRM.....

      by Carmel Schvartzman


כתב: כרמל שוורצמן

Tuesday, January 5, 2016

How to Fix the Dynamics CRM ERROR Public assembly must have public key token

In this article we see Step by step How to Fix the Dynamics CRM ERROR Public assembly must have public key token , in both CRM 2011 and CRM 2013 and CRM 2015 .
Several errors can be thrown by Microsoft Dynamics CRM while registering a custom plugin at the CRM server.
Usually the error message will express "Public assembly must have public key token".

We'll see here in only 10 minutes how to fix this error , which is shown this way , for example :

Public assembly must have public key token

Public assembly must have public key token


How to Fix the Dynamics CRM ERROR Public assembly must have public key token


Usually, you will get this kind of error while registering a new custom plugin using the Plugin Registration Tool of the Microsoft Dynamics CRM SDK:

Public assembly must have public key token


TO FIX THIS ERROR, reopen your Visual Studio project , and open the Properties window at the "Signing" tab , as follows :

Public assembly must have public key token

There, check the "Sign the assembly" option.
Optionally, you can sign the assembly using a password.

Then, REBUILD your project, and go to the BIN folder to get the assembly.
Open the Plugin Registration Tool, and specify the location of the assembly:

Public assembly must have public key token


Then, set the isolation to "None", sot that there will be no limitations to the plugin functionality.
Also , select the database option as the place to store the assembly:

Public assembly must have public key token


And click on the "Register Selected Plugins" button:

Public assembly must have public key token




This time, because the plugin includes a signature, CRM will accept the registration:


Public assembly must have public key token




The steps are usually as following:
0) reopen your Visual Studio project
1) open the Properties window at the "Signing" tab
2) check the "Sign the assembly" option
3) sign the assembly using a password (optional)
4) REBUILD your project
5) go to the BIN folder to get the assembly
6) Open the Plugin Registration Tool
7) specify the location of the assembly
8) click on the "Register Selected Plugins" button


Happy CRM.....

      by Carmel Schvartzman


כתב: כרמל שוורצמן