Microsoft Dynamics CRM 2011

Microsoft Dynamics CRM 2011
Showing posts with label Dynamics CRM. Show all posts
Showing posts with label Dynamics CRM. Show all posts

Wednesday, December 30, 2020

How to find and debug your custom Javascript files in Dynamics CRM / 365

In this article we describe Step by step How to find and debug your custom Javascript files in Dynamics CRM / 365 in 5 minutes.
After you have coded you javascript files, you want to find them for debugging purposes. It could be a not easy task to find them between the hundreds of source files that Dynamics 365 will load to the browser:




How to find and debug your custom Javascript files in Dynamics CRM / 365

To debug quickly your javascript files, just follow this steps:

1) Open the FORM of the Entity your are working on, and go to the Properties of the Form. Open the Web Resources and find the JAVASCRIPT LIBRARY that you want to debug. Double-click it to open the editor:



2) Once opened the Editor, type into your  javascript file , the "debugger; " command:



3) Save it, save the Form, Publish it and open the Developer's Tools of the browser:


4) Then , just perform the Click or anything else that would trigger your javascript code: from here, you can add breakpoints to stop the script execution.
That's all...
In this article we've seen Step by step How to find and debug your custom Javascript files in Dynamics CRM / 365 in 5 minutes.
Enjoy Microsoft Dynamics 365 CRM!

by Carmel Schvartzman

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










    Saturday, March 21, 2020

    SOLVED ERROR "There is a problem communicating with the Microsoft CRM Server" when configuring Microsoft Dynamics CRM for Outlook

    In this article we describe Step by step How to solve the ERROR "There is a problem communicating with the Microsoft CRM Server"  when configuring Microsoft Dynamics CRM for Outlook.
    This error can occur during/after the installation the Microsoft Dynamics CRM client addon for Microsoft Office Outlook.After getting this message, you might this other one, while clicking the OK button:
    "An error occurred loading Microsoft CRM functionality. Try restarting Microsoft Outlook. Contact your system administrator if error persists."



     How to solve the ERROR "There is a problem communicating with the Microsoft CRM Server"  when configuring Microsoft Dynamics CRM for Outlook



    To resolve this problem, follow this steps:

    1) Open the IE Options,and click the Security tab. Click Local intranet >> Sites, and then Advanced.
    Then type the IP of the Microsoft CRM server, and click OK three times. Restart Microsoft Outlook.


    2) Open regedit, and locate the following subkey: HKEY_CURRENT_USER\ Software\Microsoft\MSCRMClient. There, check for the correct URL of your Microsoft CRM server.

    If these steps were NOT enought , continue with the following:

    3) Inside Dynamics CRM, open Settings >> Business Unit Settings >>  Users, and locate the user who is experiencing this error. Click the information side tab, and there clear the Restricted Access Mode check box.

    4) Open CONTROL from the Start of your PC, and open User Accounts >>> Advanced tab.
    Click Manage Passwords, and proceed to delete all CRM passwords and usernames there.


    That's all...
    In this article we've seen Step by step  How to solve the ERROR "There is a problem communicating with the Microsoft CRM Server"  when configuring Microsoft Dynamics CRM for Outlook.
    Enjoy Microsoft Dynamics 365 CRM!

    by Carmel Schvartzman

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













      Tuesday, April 16, 2019

      Dynamics 365 - How to Create a MANY-TO-ONE related Entity record using Web API and Javascript in 5 minutes

      In this article we describe Step by step How to Create a MANY-TO-ONE related Entity record using Web API and Javascript in 5 minutes.
      This Web Resource uses Bootstrap and JQuery , to issue HTTP POST and HTTP PATCH requests to a Dynamics 365 Organization, using the Web Api, in order to Create a new Contact record, related to a current Phonecall. 

      The UI looks like this :










      How to Create a MANY-TO-ONE related Entity record using Web API and Javascript in 5 minutes  



      There will be 2 functions, one for creating a new Contact record with HTTP POST , like this :





      And the second function, in order to UPDATE the current Phonecall record, setting its Contact reference regardingobjectid_contact to the guid of the newly created Contact :






      The following is the whole Web Resource, to be copied as a building block to your Dynamics Organization :


      <html>
      <head>
          <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

          <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
          <script>

              // Create a MANY-TO-ONE relationship :  Créer une relation plusieurs-à-un phonecalls-contact :
              var fnPATCHRelatedEntity = (newEntityId) => {
                  //debugger;
                  var entity = {};
                  entity["regardingobjectid_contact@odata.bind"] = "/contacts(" + newEntityId + ")";
                  let id = parent.Xrm.Page.data.entity.getId().replace('{', '').replace('}', '');
                  // In case you want to modify another attribute :  Au cas ou tu veux modifier un autre attribut :
                  // entity.phonenumber = "0546589251";

                  parent.$.ajax({     //  We can use HTTP PUT whenever we need to modify only ONE attribute
                      type: "PATCH",  //  on peut utiliser le verbe HTTP PUT , dans le cas de modification de 1 seul attribut
                      contentType: "application/json; charset=utf-8",
                      datatype: "json",
                      url: parent.Xrm.Page.context.getClientUrl() + "/api/data/v8.2/phonecalls(" + id + ")",
                      data: JSON.stringify(entity),
                      beforeSend: function (XMLHttpRequest) {
                          XMLHttpRequest.setRequestHeader("OData-MaxVersion", "4.0");
                          XMLHttpRequest.setRequestHeader("OData-Version", "4.0");
                          XMLHttpRequest.setRequestHeader("Accept", "application/json");
                      },
                      async: true,
                      success: function (data, textStatus, xhr) {
                          parent.Xrm.Utility.alertDialog('Phonecall Updated with MANY-TO-ONE relationship!!');
                      },
                      error: function (xhr, textStatus, errorThrown) {
                          parent.Xrm.Utility.alertDialog(textStatus + " " + errorThrown);
                      }
                  });

              }

              var fnCreateContact = () => {
                  //debugger;
                  var entity = {};
                  entity.address1_telephone1 = document.getElementById("Phone").value;
                  entity.emailaddress1 = document.getElementById("Email").value;
                  entity.firstname = document.getElementById("FirstName").value;
                  entity.lastname = document.getElementById("LastName").value;

                  parent.$.ajax({
                      type: "POST",
                      contentType: "application/json; charset=utf-8",
                      datatype: "json",
                      url: parent.Xrm.Page.context.getClientUrl() + "/api/data/v8.2/contacts",
                      data: JSON.stringify(entity),
                      beforeSend: function (XMLHttpRequest) {
                          XMLHttpRequest.setRequestHeader("OData-MaxVersion", "4.0");
                          XMLHttpRequest.setRequestHeader("OData-Version", "4.0");
                          XMLHttpRequest.setRequestHeader("Accept", "application/json");
                      },
                      async: true,
                      success: function (data, textStatus, xhr) {
                          let uri = xhr.getResponseHeader("OData-EntityId");
                          let regExp = /\(([^)]+)\)/;
                          let matches = regExp.exec(uri);
                          let newEntityId = matches[1];
                          if (newEntityId != null) {
                              // Créer une relation plusieurs-à-un phonecalls-contact :
                              fnPATCHRelatedEntity(newEntityId);
                          }


                          document.getElementById('btnCreateContact').classList.add('disabled');
                      },
                      error: function (xhr, textStatus, errorThrown) {
                          parent.Xrm.Utility.alertDialog(textStatus + " " + errorThrown);
                      }
                  });
              }


          </script>

      </head>
      <body style="direction: rtl; overflow-wrap: break-word;">

          <div class="container">
              <div class="jumbotron">
                  <h3>Create Contact</h3>
                  <p></p><h5>This function creates a new Contact related to the current Phonecall through a One-To-Many relationship</h5><p></p>
                  <table style="font:12px;border-spacing:3px;margin:5px;">
                      <tbody>
                          <tr>
                              <td>First Name: </td>
                              <td><input type="text" id="FirstName" value="Bender"></td>
                          </tr>
                          <tr>
                              <td>Last Name: </td>
                              <td><input type="text" id="LastName" name="LastName" value="Rodriguez"></td>
                          </tr>
                          <tr><td>Email: </td><td><input type="text" id="Email" value="www.bender.com"></td></tr>
                          <tr>
                              <td>Phone: </td>
                              <td><input type="text" id="Phone" name="Phone" value="123456789"></td>
                          </tr>
                      </tbody>
                  </table>

                  <button id="btnCreateContact" onclick="fnCreateContact()" type="button" class="btn btn-primary">Create Contact</button>

              </div>
          </div>
      </body>
      </html>










      That's all...
      In this article we've seen Step by step How to Create a MANY-TO-ONE related Entity record using Web API and Javascript in 5 minutes.
      Enjoy Microsoft Dynamics 365 CRM!

      by Carmel Schvartzman

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

      Step by step How to Install the CRM REST Builder in your Dynamics CRM 365 in 5 minutes

      In this article we describe Step by step How to Install the CRM REST Builder in your Dynamics CRM 365 in 5 minutes.
      The CRM REST Builder is an open source creation by  Jason Lattimer. It will give you the chance of getting the REST OData code that you need, both using JQuery or XMLHttpRequest, automatically and avoiding to fall on errors. The Builder enables you to perform WEB API OData REST request to create One to Many , Many to One and Many to Many relationships, asynchronously:



      How to Install the CRM REST Builder in your Dynamics CRM 365 in 5 minutes

      1) Download the REST BUILDER:
      Browse to the Jason Lattimer's Github , and download the Builder , according to your Dynamics CRM version: https://github.com/jlattimer/CRMRESTBuilder/releases



      2) Import the Managed Solution to your Dynamics 365:
      Open your solutions screen, and import the REST Builder solution:



      3) Open the REST BUILDER:
      After refreshing the Solutions form, you will see a button on the top of the form. Open it to see the Builder:





      4) Create your REST request:

      Create your request, and copy it to the web resource that will be called from your entity form:








      That's all...
      In this article we've seen Step by step How to Install the CRM REST Builder in your Dynamics CRM 365 in 5 minutes.
      Enjoy Microsoft Dynamics 365 CRM!

      by Carmel Schvartzman

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










        Sunday, February 10, 2019

        How to re-enable the Dynamics 365 for Outlook Client in Outlook

        In this article we describe Step by step How to re-enable the Dynamics 365 for Outlook Client in Outlook.

        How to re-enable the Dynamics 365 for Outlook Client in Outlook


        In case that your Outlook crashed because of some  Dynamics 365 for Outlook Client , while reloading Outlook, you will be prompted to disable the add-in that caused the problem.

        Usually, the Dynamics 365 for Outlook Client addon will be disabled.
        The problem is, how to re-enable it?

        The solution is, by opening the Dynamics 365 for Outlook Client Diagnostics window.

        To do so, go to the Start , Programs, and locate the Diagnostics:



        On the opened window, go to the second tab "Advanced" :





        In the "Advanced" tab, click on "Enable" :



         Reopen Outlook , and the Dynamics 365 for Outlook Client will be there.



        That's all...Enjoy Dynamics CRM

        by Carmel Schvartzman

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










          Wednesday, July 18, 2018

          Dynamics CRM Errors when importing unmanaged solution

          In this article we see Step by step How to fix Dynamics CRM Errors when importing unmanaged solution , in both CRM 2011 and CRM 2013 .
          Several errors can be thrown by Microsoft Dynamics CRM while importing an unmanaged solution from test to production environments, such as "This import has failed because a different entity with the identical name" , or "Field Is Not Unique"...
          Usually the causes are differences of schema between fields or entities.

          First of all, try to check this 2 things:

          1) Schema name and name : have the fields/entities EXACTLY (letter capitalization) the same schema names? (  new_MyField < > new_myfield ) 

          2) Schema data types: have the fields/entities EXACTLY the same type? (nvarchar = nvarchar, int = int)

          We'll see here in only 10 minutes how to perform a search for the DYNAMICS CRM API web service error codes , such as "0x80044150" or "0x80041a06" , for example :

          Errors when importing unmanaged solution
          Dynamics CRM Errors importing unmanaged solution


          How to fix Dynamics CRM Errors when importing unmanaged solution


          Usually, you will get this kind of error while importing a CRM solution:

          Dynamics CRM Errors when importing unmanaged solution


          The steps are usually as following:
          0) open the importing error file and make a search for "0x" to get the error!!!
          1) get the hexadecimal error code for the Entity and delete the hexadecimal prefix "0x"
          2) search the web for the error without the "0x" prefix
          3) re-build any custom Field which has an schema name ("new_myfield") difference
          4) re-build any custom Field which has a type difference


          1) Step #0: open the log file to find the error :

          Dynamics CRM Errors when importing unmanaged solution



          2) Step #1: get the hexadecimal Error Code & delete its "0x" prefix :


          Dynamics CRM when importing unmanaged solution




          3) Step #2: search the Web for the code but without the prefix "0X":


          Make a search for "DYNAMICS CRM API web service error codes" , and append the error code:

          CRM Errors when importing solution





          Dynamics CRM Errors when importing unmanaged

          Remember: as long as Microsoft Dynamics CRM uses GUIDs , and they are different between a development environment to a production environment, the only way it has to identify an Entity is its schema name and its type !!!!!!



          Happy CRM.....

                by Carmel Schvartzman


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

          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


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

          Sunday, July 5, 2015

          How to Add a custom Button to a CRM 2013 Web Form

          In this article we see Step by step How to Add a custom Button to a CRM 2013 Web Form .
          We'll review here in only 5 minutes how to create an HTML5 Button at the client side Front End , using only javascript, HTML and CSS3:




          The steps are as following:
          1) create a CRM field to be the container of the button(set its text as ".")
          2) create a web resource containing the following javascript
          3) call the web resource from your CRM form, sending as argument the name of your container field.


          1) Step #1: create a CRM field to be the container of the button:


          The button will be located at the CRM field (called "sFieldName" in the following code).
          Try to create a new CRM field to parent the button, and set "." as its text. This way the button will fill the field, and you can locate it wherever you want inside the CRM form.

          2) Step #2: create a web resource containing the following javascript:

          This is the code that creates the Button:
          It just retrieves the HTML5 element wrapping the CRM field where you want the button appended to, and creates an element with a custom button:





          Create a Web Resource with the following javascript code (note: this code does not depend on jQuery or any other framework: you can copy-paste it as it is):

          function fnXRMClientButton(sFieldName)
          {   // sFieldName : "new_somefield"
              
              if (document.getElementById(sFieldName) != null) {
                   sFieldName = "field" + sFieldName;
                   if (document.getElementById(sFieldName) == null)
                   {
                      var oParentElement = document.getElementById(sFieldName + "_d");
                      oContainerElement = document.createElement("oContainerElement");
                      oParentElement.appendChild(oContainerElement, oParentElement);
                      
                      var btn = document.createElement("button");
                      var txt = document.createElement("span");
                      txt.innerText = "BUTTON TEXT";            
                      btn.id = "btnCallAction";
                      btn.appendChild(txt);
                      btn.style.margin = "10px";
                      btn.style.padding = "5px";
                      btn.style.width = "300px";
                      btn.style.height = "50px";
                      btn.style.textAlign = "center";
                      btn.style.borderRadius = "5px";
                      btn.style.textShadow = "1px 1px 2px #FFF";
                      btn.style.color = "#000";
                      btn.style.boxShadow = "#a8a3a3 5px 5px 1px";           
                      btn.style.border = "1px double #dcdcdc";           
                      btn.style.background = "#f5f5f5";
                      btn.style.font = "600 14px Tahoma";
                      oContainerElement.appendChild(btn);


                      document.getElementById(sFieldName).style.width = "0%";
                      btn.onclick = function () {
                          OnClickActionFunction(oContainerElement);

                      };

                  }
              }
          }


          3) Step #3: call the web resource from your CRM form, sending as argument the name of your container field:


          fnXRMClientButton("new_somefield")


          That's all.  

          Happy programming.....

                by Carmel Schvartzman


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



          Sunday, August 18, 2013

          How to programmatically retrieve a Dynamic Marketing List from inside a Plugin in Dynamics CRM

          by Carmel Schvartzman
          1. In this walkthrough we will learn Step-By-Step How to programmatically retrieve a Dynamic Marketing List from inside a Plugin in Dynamics CRM. The DYNAMIC Marketing List is  a CRM 2011 feature that enables to fetch an on-the-fly list, not know in advance, of items according to some pre-determined requirements defined in a QUERY.

          How to programmatically retrieve a Dynamic Marketing List from inside a Plugin in Dynamics CRM

          1. First, start VISUAL STUDIO 2010 and create a WF project:How to programmatically retrieve a Dynamic Marketing List from inside a Plugin in Dynamics CRM
          2. Next, delete the XAML file,
            2
            and create a CS. new class "DynamicMarketingListActivity" (SHIFT-ALT-C):3
          3. IMPORTANT: the class we just created IS NOT PUBLIC: we ough to declare it PUBLIC , elsewhere we'll get a SETUP ERROR at the time of deploying the plug-in to the CRM server:4
          4. We want to create a custom workflow, so we'll inherit from the base class CodeActivity: let's also add the System.Activities using directive:5
          5. The CodeActivity class is ABSTRACT, that means we'll have to implement in this case  the method "Execute":
            6
          6. Delete the "throw new" code. We'll write code of our own:
            programmatically retrieve a Dynamic Marketing List from inside a Plugin in Dynamics CRM
          7. Now we'll write our custom activity. First of all, we'll need a CONTEXT that allows us to communicate with the CRM webservices. We'll need the CRM's  IOrganizationService, an interface that provides programmatic access to the metadata and data for our CRM Organization. In order to do that, we'll use the IOrganizationServiceFactory,  as stated at the MSDN documentation:  we'll create it using the  GetExtension<......>() method of the context. So write the following code:
            8
            However, if after writing the code, you BUILD the solution (F6), you'll face the "Are you missing a using directive or an assembly reference":
            9
            That's because we have to tell VS where the CRM specific interfaces that we just  wrote are. They are included in the following two assemblies : Microsoft.Xrm.Sdk.dll and Microsoft.Xrm.Workflow.dll. So add  the references to both DLLs (you can find them in the CRM2011 SDK Bin folder : download from here):
            10
            Again, while REBUILDING the solution, we get an error message: "...XRM does not exists...":
            11 That's because the target framework default option for a new workflow project is "CLIENT PROFILE": go to PROPERTIES and under "APPLICATION" change the target framework to ".NET Framework 4":
            12
            Rebuild the solution.
          8. Now we need to sign the assembly  using the "signing" tab of the project's  properties:27
          9. Using the IOrganizationServiceFactory, we'll create an instance of the IOrganizationService:
            13
          10. We'll also need to call another CRM web service, which will allow us to get accurate info about what happened in case of error: it's called ITracingService and again we'll create it using the  GetExtension<ITracingService>() method of the context:14Rebuild the solution. We have all we need to use our workflow.
          11. Now let's add some METADATA: the CRM environment uses this metadata at runtime to link our code to the workflow engine. This way we can also declare a parameter as REQUIRED and even set DEFAULT values just in case the user do not provide them.
            Usually, plug-ins need INPUT and OUTPUT parameters. We'll add both of them to our plug-in. For the INPUT parameter, let's add a public InArgument<string> automatic property:15Here we declare our "PluginInput" property to be an InArgument of type string, that the CRM workflow engine will know by the name of "PluginInput" , and which its default value is set as "Default Plugin Input". The parameter name will appear in the workflow form assistant, so that the users can map the attribute as anWe can also state that the input parameter will be required, using the following attribute:
            [RequiredArgument]Output parameters are declared the same way as input parameters:16
            And in the code, we use this properties the following way:17That means, we GET the input string parameter calling the Get<some type >(context) method of the INPUT property, and SET the OUTPUT parameter using the Set(context, <some object>) method of the output parameter.
          12. OK, we have our workflow built. This plug-in will receives a Marketing List and do some custom action over each of the list items. But since those items aren't there yet, because we're talking of a DYNAMIC list, HOW DO WE GET THE RECORDS TO UPDATE?All we need to do is get the GUID of the DYNAMIC LIST. With this ID we'll get the FETCH XML declared at the graphic CRM UI when the Marketing List was created:18Also, we get the Entity type we receives from the CRM engine: as we declared when creating the workflow, the Entity will be a "Marketing List":19Accordingly we get a Marketing List as the 'PRIMARY ENTITY'. We'll get this primary entity GUID and use it to retrieve the dynamic QUERY : this query is an object of type FETCHEXPRESSION: In order to create an instance of FetchExpression, we need to add a using directive to our workflow:20
            The same goes for the class ColumnSet: we need to add a reference to the DLL System.Runtime.Serialization:22
            We'll get this primary entity GUID and use it to retrieve the dynamic QUERY:23
            After we got the guid of the dynamic Marketing list, we are ready to get the QUERY that defines who are the MEMBERS of the list:
            24
            A dynamic Marketing list has an "query" attribute , which is not present in case of a STATIC Marketing list. Using the organization web service's  Retrieve() method, we fetch the "query" attribute:
            25
            Accordingly, we instantiate a FetchExpression object with the "query" string. Next, we just fetch the members of the list using the RetrieveMultiple() method.
            Now that we have the guids of the dynamic list members, we can retrieve them and apply the changes we want to each record:
            26
          13. The next stage is to deploy the DLL wokflow to the Crm server. We need the Plugin Registration Tool that comes with the CRM 2011 SDK, therefore copy that GUI to some directory at the CRM server:000I copied the app to the C:\Plugintool directory.
          1. Double click the PluginRegistration tool:1
          2. Now, press CONNECT to discover your CRM webservice:2If your CRM server hosts more than one Organization, select the one to wich you developed your plug-in
          3. Check that the selected CRMService URL is the one you want to deploy your plug-in
          4. Now press "REGISTER" and next "REGISTER NEW ASSEMBLY":4
          Now select the assembly you want to deploy:
          6
          It's strongly recommended that you set up the ISOLATION MODE to "SANDBOX": the SANDBOX feature gets code executed in an isolated and trusted environment. In the case your plug-in consumes too much server resources, SANDBOX mode will remove it from the event pipeline where you registered  your code. Also, the same will be done in case of continuous failing.
          IMPORTANT: the assembly can be stored in the DISK or in the DATABASE. At the development stage, it's recommended you store it at the DISK, because there you can also copy the .PDB file used for debugging purposes. Later, when you finished testing your code, YOU MUST DEPLOY IT TO THE DATABASE!! Why? Some reasons are:
          • The assemblies registered on database can be included in a solution hosted in sandbox or in CRM ONLINE.
          • If your CRM server is load balancing, storing the DLLs in DATABASE will allow CRM to automize the process of updating and deploying changes.
          •  There's no need to restart the CRM servicesmaking IISRESET on the applicationpool because the update of an assembly will take effect automatically after you press the UPDATE button.7So instead of selecting "DATABASE" select the option "DISK" for now.
           That's all
          This tutorial is about How to programmatically retrieve a Dynamic Marketing List from inside a Plugin in Dynamics CRM
          Happy programming    :-)