XmlException: An error occurred while parsing EntityName in CRM Plugin

I had written a pre-update plugin, it was working properly on my environment.

But after sending it across to the client, after he had deployed it we started getting the below mentioned error.

“XmlException: An error occurred while parsing EntityName”

We were actually passing secure configuration information to the plugin in the following format

<Config>

<url>http://CrmServer/MSCRMServices/2007/CrmService.asmx</url>

<orgname>OrgName</orgname>

<username>UserName</username>

<password>Password</password>

<domain>Domain</domain>

</Config>

And the issue was the password that was being used, it had ‘&’ character, which we then replaced with ‘&amp;’ and the error got resolved.

Hope it helps!

Filtered Lookup in CRM 2011

To get the filtered lookup functionality in CRM 2011 we can make use of the

addCustomView Method of Xrm.Page.ui control.


Something similar to this

Here we have a custom entity name Case which has 1-n relationship with Contact Entity.

Now we want to show only those contact records in lookup which are associated with a particular case record.

We can add the code to the onload of the Entity.

// View ID --> Generate and Assign a new guid.

var viewId = "{C0F1DD64-1BF3-450D-BCDE-DF4732DE1606}";

// Set the entity name
 var entityName = "contact";
 // Give a meaningful name to the custom view
 var viewDisplayName = "Case Member View";

// Create the Advanced find query and download the fetch xml
var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
"<entity name='contact'>" +
"<attribute name='fullname' />" +
" <attribute name='contactid' />" +
"<order attribute='fullname' descending='false' />" +
"<filter type='and'>" +
"<condition attribute='new_caseid' operator='eq' uiname='new case' uitype='new_case' value="+caseID+"/>" +
"</filter>" +
"</entity>" +
"</fetch>";

// specify the layout for the results and which field to display
var layoutXml = "<grid name='resultset' " +
"object='1' " +
"jump='name' " +
"select='1' " +
"icon='1' " +
"preview='1'>" +
"<row name='result' " +
"id='contactid'>" +
"<cell name='fullname' " +
"width='100' />" +
"</row>" +
"</grid>";
// specify the schemaname of the lookup control
var lookupControl = Xrm.Page.ui.controls.get('new_clientid');
// set the parameters

lookupControl.addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, true);

Sample Code to add a custom button to a custom group in CRM 2011

Hi,

Following is the sample code to add a custom button to a custom group for a custom entity (new_test)

The button gets displayed only when the record is created.

We need to define Display Rule for that in Rule Definitions and use that rule within Command Defintion for the Button


<RibbonDiffXml>
  <CustomActions>
   <CustomAction Id="Sample.Form.new_test.CustomTab.CustomAction" Location="Mscrm.Tabs._children" Sequence="40">
    <CommandUIDefinition>
     <Tab Id="Sample.Form.new_test.CustomTab" Command="Sample.Form.new_test.CustomTab" Title="My First Custom Tab" Description="Finally managed to put my first custom tab" Sequence="40">
      <Scaling Id="Sample.Form.new_test.CustomTab.Scaling">
       <MaxSize Id="Sample.Form.new_test.CustomTab.FirstGroup.MaxSize" GroupId="Sample.Form.new_test.CustomTab.FirstGroup" Sequence="10" Size="LargeMedium"/>
      </Scaling>
      <Groups Id="Sample.Form.new_test.CustomTab.Groups">
       <Group Id="Sample.Form.new_test.CustomTab.FirstGroup" Command="Sample.Form.new_test.FirstGroup" Sequence="10" Title="Custom Group" Template="Mscrm.Templates.3.3">
        <Controls Id="Sample.Grid.new_test.CustomTab.FirstGroup.Controls">
         <Button Id="Sample.Form.new_test.CustomTab.FirstGroup.FirstButton" ToolTipTitle="My First Button Tool Tip" ToolTipDescription="My First Button Tool Tip Description" Command="Sample.Form.new_test.FirstButton" Sequence="10" LabelText="First Button" Alt="Alt First Button" TemplateAlias="o1"/>
        </Controls>
       </Group>
      </Groups>
     </Tab>
    </CommandUIDefinition>
   </CustomAction>
  </CustomActions>
  <Templates>
   <RibbonTemplates Id="Mscrm.Templates"/>
  </Templates>
  <CommandDefinitions>
   <CommandDefinition Id="Sample.Form.new_test.CustomTab">
    <EnableRules>
     <EnableRule Id="Mscrm.Enabled "/>
    </EnableRules>
    <DisplayRules>
     </DisplayRules>
    <Actions/>
   </CommandDefinition>
   <CommandDefinition Id="Sample.Form.new_test.FirstGroup">
    <EnableRules>
     <EnableRule Id="Mscrm.Enabled "/>
    </EnableRules>
    <DisplayRules>
     </DisplayRules>
    <Actions/>
   </CommandDefinition>
   <CommandDefinition Id="Sample.Form.new_test.FirstButton">
    <EnableRules>
     <EnableRule Id="Mscrm.Enabled "/>
    </EnableRules>
    <DisplayRules>
     <DisplayRule Id="Sample.new_test.form.FormStateNotNew.DisplayRule">
       </DisplayRule>
    </DisplayRules>
    <Actions>
     </Actions>
   </CommandDefinition>
  </CommandDefinitions>
  <RuleDefinitions>
   <TabDisplayRules>
    <TabDisplayRule TabCommand="Sample.Form.new_test.CustomTab">
     <EntityRule EntityName="new_test" Context="Form" AppliesTo="PrimaryEntity"/>
    </TabDisplayRule>
   </TabDisplayRules>
   <DisplayRules>
    <DisplayRule Id="Sample.new_test.form.FormStateNotNew.DisplayRule">
     <FormStateRule State="Create" InvertResult="true"/>
    </DisplayRule>
   </DisplayRules>
   <EnableRules/>
  </RuleDefinitions>
  <LocLabels/>
 </RibbonDiffXml>

Hope it helps !

Sample Code to add a custom tab to a custom entity in CRM 2011

Hi,

Customizing the Ribbon interface in CRM 2011 is not that easy, if we compare it to the ISV.CONFIG.

Here i am posting a sample xml file that we can use to create a custom tab within an entity.

Suppose the schema name of the entity is new_test, so use the following code to add a custom tab to it.

I am posting the RibbonDiffXml part

<RibbonDiffXml>
 <CustomActions>
  <CustomAction Id=”Sample.Form.new_test.CustomTab.CustomAction” Location=”Mscrm.Tabs._children” Sequence=”40″>
   <CommandUIDefinition>
    <Tab Id=”Sample.Form.new_test.CustomTab” Command=”Sample.Form.new_test.CustomTab” Title=”My First Custom Tab” Description=”Finally managed to put my first custom tab” Sequence=”40″>
     <Scaling Id=”Sample.Form.new_test.CustomTab.Scaling”>
      <MaxSize Id=”Sample.Form.new_test.CustomTab.FirstGroup.MaxSize” GroupId=”Sample.Form.new_test.CustomTab.FirstGroup” Sequence=”10″ Size=”LargeMedium”/>
     </Scaling>
     <Groups Id=”Sample.Form.new_test.CustomTab.Groups”>
      <Group Id=”Sample.Form.new_test.CustomTab.FirstGroup” Command=”Sample.Form.new_test.FirstGroup” Sequence=”10″ Title=”Custom Group” Template=”Mscrm.Templates.3.3″>
       <Controls Id=”Sample.Grid.new_test.CustomTab.FirstGroup.Controls”/>
      </Group>
     </Groups>
    </Tab>
   </CommandUIDefinition>
  </CustomAction>
 </CustomActions>
 <Templates>
  <RibbonTemplates Id=”Mscrm.Templates”/>
 </Templates>
 <CommandDefinitions>
  <CommandDefinition Id=”Sample.Form.new_test.CustomTab”>
   <EnableRules>
    <EnableRule Id=”Mscrm.Enabled “/>
   </EnableRules>
   <DisplayRules>     
    </DisplayRules>
   <Actions/>
  </CommandDefinition>
  <CommandDefinition Id=”Sample.Form.new_test.FirstGroup”>
   <EnableRules>
    <EnableRule Id=”Mscrm.Enabled “/>
   </EnableRules>
   <DisplayRules>
    </DisplayRules>
   <Actions/>
  </CommandDefinition>
 </CommandDefinitions>
 <RuleDefinitions>
  <TabDisplayRules>
   <TabDisplayRule TabCommand=”Sample.Form.new_test.CustomTab”>
    <EntityRule EntityName=”new_test” Context=”Form” AppliesTo=”PrimaryEntity”/>
   </TabDisplayRule>
  </TabDisplayRules>
  <DisplayRules/>
  <EnableRules/>
 </RuleDefinitions>
 <LocLabels/>
</RibbonDiffXml>

Hope it helps !

using CrmSvcUtil

Use CrmSvcUtil to generate the strongly types entity and datacontext classes

crmsvcutil

/connectionString:"Authentication Type=Integrated; Server=http://servername/orgname"

/out:"Xrm.cs" /namespace:"Xrm.solution"

/dataContextClassName:"xrm"

conntectionString–> specifies the connection string.
out –> determines the name of the .cs or .xml output file and whether there is one file or one per entity.To generate one file per entity omit .cs or .xml from the file name.
namespace –> to specify the namespace
dataContextClassName –> to specify the name of the dataContext class.

Add references to the following dlls in the project

  • System.Data.Entity, System.Data.Services, System.Data.Services.Client.
  • System.Web.Services.
  • Microsoft.Crm.Sdk, Microsoft.Crm.SdkTypeProxy.dll, Microsoft.Crm.SdkTypeProxy.XmlSerializers
  • Microsoft.Xrm.Client, Microsoft.Xrm.Portal, Microsoft.Xrm.Portal.Files

Add the generated Xrm.cs file to the project.

Add the connection string information in the config file of the application

<add name="CRMOnPremise" connectionString="Authentication Type=Integrated; Server=http://servername/orgname" />

Add following using Statements

using Xrm;
using Xrm.solution;
using Microsoft.Crm.Sdk;
using Microsoft.Crm.SdkTypeProxy;

And the code for creating a new custom entity record.

            new_test testEntity1 = new new_test();
            testEntity1.new_name = "Nishant";
            testEntity1.new_lastname = "Rana";
            myXrm.AddTonew_tests(testEntity);
            myXrm.SaveChanges();

 

or could also be written as

            // create the instace of DataContext class named xrm
            var myXrm = new xrm("CRMOnPremise");
          
// use concept of Implicitly type local variable 
           
// and object intializer
            var testEntity = new new_test()
            {
                new_name = "Nishant",
                new_lastname = "Rana"
            };
            myXrm.AddTonew_tests(testEntity);
            myXrm.SaveChanges();

 
 

Similarly to update a record and delete a record we need to use

UpdateObject() and DeleteObject() function followed by call to

SaveChanges() method.

Bye.