Adding Custom Tab with Custom Button in CRM 2011


Hi,

There is one walkthrough in CRM SDK — Add a Custom Tab to a Specific Entity.

I have modified it to work for only the form of the entity.

And the tab and the button would appear only in case of existing record (not while record is getting created)

To use the code just replace new_case with the name of the entity and get the images from the walkthrough folder.

<RibbonDiffXml>
<CustomActions>
<CustomAction Id=”Sample.Form.new_case.CustomTab.CustomAction” Location=”Mscrm.Tabs._children” Sequence=”40″>
<CommandUIDefinition>
<Tab Id=”Sample.Form.new_case.CustomTab” Command=”Sample.Form.new_case.CustomTab” Title=”Eligibility” Description=”Eligibility” Sequence=”40″>
<Scaling Id=”Sample.Form.new_case.CustomTab.Scaling”>
<MaxSize Id=”Sample.Form.new_case.CustomTab.FirstGroup.MaxSize” GroupId=”Sample.Form.new_case.CustomTab.FirstGroup” Sequence=”10″ Size=”LargeMedium”/>
</Scaling>
<Groups Id=”Sample.Form.new_case.CustomTab.Groups”>
<Group Id=”Sample.Form.new_case.CustomTab.FirstGroup” Command=”Sample.Form.new_case.FirstGroup” Sequence=”10″ Title=”Eligibililty” Template=”Mscrm.Templates.3.3″>
<Controls Id=”Sample.Grid.new_case.CustomTab.FirstGroup.Controls”>
<Button Id=”Sample.Form.new_case.CustomTab.FirstGroup.FirstButton” ToolTipTitle=”Add Clients” ToolTipDescription=”To add clients to the case” Command=”Sample.Form.new_case.FirstButton” Sequence=”10″ LabelText=”Add Clients” Alt=”Add Clients” Image16by16=”$webresource:sample_/icons/1Icon16x16.png” Image32by32=”$webresource:sample_/icons/1Icon32x32.png” TemplateAlias=”o1″/>
<Button Id=”Sample.Form.new_case.CustomTab.FirstGroup.SecondButton” ToolTipTitle=”Manage Relationship” ToolTipDescription=”To manage relationship between the members” Command=”Sample.Form.new_case.SecondButton” Sequence=”10″ LabelText=”Manage Relationship” Alt=”Manage Relationship” Image16by16=”$webresource:sample_/icons/2Icon16x16.png” Image32by32=”$webresource:sample_/icons/2Icon32x32.png” TemplateAlias=”o1″/>
<Button Id=”Sample.Form.new_case.CustomTab.FirstGroup.ThirdButton” ToolTipTitle=”Add Programs” ToolTipDescription=”To add program request to the case” Command=”Sample.Form.new_case.ThirdButton” Sequence=”10″ LabelText=”Add Programs” Alt=”Add Programs” Image16by16=”$webresource:sample_/icons/3Icon16x16.png” Image32by32=”$webresource:sample_/icons/3Icon32x32.png” TemplateAlias=”o1″/>
<Button Id=”Sample.Form.new_case.CustomTab.FirstGroup.FourthButton” ToolTipTitle=”Determine Eligibility” ToolTipDescription=”To determine eligibility” Command=”Sample.Form.new_case.FourthButton” Sequence=”10″ LabelText=”Determine Eligibility” Alt=”Determine Eligibility” Image16by16=”$webresource:sample_/icons/4Icon16x16.png” Image32by32=”$webresource:sample_/icons/4Icon32x32.png” TemplateAlias=”o1″/>
</Controls>
</Group>
</Groups>
</Tab>
</CommandUIDefinition>
</CustomAction>
</CustomActions>
<Templates>
<RibbonTemplates Id=”Mscrm.Templates”/>
</Templates>
<CommandDefinitions>
<CommandDefinition Id=”Sample.Form.new_case.ThirdButton”>
<EnableRules>
<EnableRule Id=”Mscrm.Enabled “/>
</EnableRules>
<DisplayRules>
<DisplayRule Id=”Sample.new_case.form.FormStateNotNew.DisplayRule3″/>
</DisplayRules>
<Actions>
<JavaScriptFunction Library=”$webresource:new_JS” FunctionName=”CallThree”/>
</Actions>
</CommandDefinition>
<CommandDefinition Id=”Sample.Form.new_case.SecondButton”>
<EnableRules>
<EnableRule Id=”Mscrm.Enabled “/>
</EnableRules>
<DisplayRules>
<DisplayRule Id=”Sample.new_case.form.FormStateNotNew.DisplayRule2″/>
</DisplayRules>
<Actions>
<JavaScriptFunction Library=”$webresource:new_JS” FunctionName=”CallTwo”/>
</Actions>
</CommandDefinition>
<CommandDefinition Id=”Sample.Form.new_case.CustomTab”>
<EnableRules>
<EnableRule Id=”Mscrm.Enabled “/>
</EnableRules>
<DisplayRules>
<DisplayRule Id=”Sample.new_case.form.FormStateNotNew.DisplayRule1″/>
</DisplayRules>
<Actions/>
</CommandDefinition>
<CommandDefinition Id=”Sample.Form.new_case.FirstButton”>
<EnableRules>
<EnableRule Id=”Mscrm.Enabled “/>
</EnableRules>
<DisplayRules>
<DisplayRule Id=”Sample.new_case.form.FormStateNotNew.DisplayRule”/>
</DisplayRules>
<Actions>
<JavaScriptFunction Library=”$webresource:new_JS” FunctionName=”CallOne”/>
</Actions>
</CommandDefinition>
<CommandDefinition Id=”Sample.Form.new_case.FourthButton”>
<EnableRules>
<EnableRule Id=”Mscrm.Enabled “/>
</EnableRules>
<DisplayRules>
<DisplayRule Id=”Sample.new_case.form.FormStateNotNew.DisplayRule4″/>
</DisplayRules>
<Actions>
<JavaScriptFunction Library=”$webresource:new_JS” FunctionName=”CallFour”/>
</Actions>
</CommandDefinition>
<CommandDefinition Id=”Sample.Form.new_case.FirstGroup”>
<EnableRules>
<EnableRule Id=”Mscrm.Enabled “/>
</EnableRules>
<DisplayRules/>
<Actions/>
</CommandDefinition>
</CommandDefinitions>
<RuleDefinitions>
<TabDisplayRules>
<TabDisplayRule TabCommand=”Sample.Form.new_case.CustomTab”>
<EntityRule EntityName=”new_case” Context=”Form” AppliesTo=”PrimaryEntity”/>
</TabDisplayRule>
</TabDisplayRules>
<DisplayRules>
<DisplayRule Id=”Sample.new_case.form.FormStateNotNew.DisplayRule3″>
<FormStateRule State=”Create” InvertResult=”true”/>
</DisplayRule>
<DisplayRule Id=”Sample.new_case.form.FormStateNotNew.DisplayRule1″>
<FormStateRule State=”Create” InvertResult=”true”/>
</DisplayRule>
<DisplayRule Id=”Sample.new_case.form.FormStateNotNew.DisplayRule”>
<FormStateRule State=”Create” InvertResult=”true”/>
</DisplayRule>
<DisplayRule Id=”Sample.new_case.form.FormStateNotNew.DisplayRule2″>
<FormStateRule State=”Create” InvertResult=”true”/>
</DisplayRule>
<DisplayRule Id=”Sample.new_case.form.FormStateNotNew.DisplayRule4″>
<FormStateRule State=”Create” InvertResult=”true”/>
</DisplayRule>
</DisplayRules>
<EnableRules/>
</RuleDefinitions>
<LocLabels/>
</RibbonDiffXml>

To get the solution

http://www.box.net/shared/sgpnqdbjot

Hope this helps !

Get quotenumber (Quote ID) on PostCreate plugin


Hi,

I got the following comment on my blog.

“I wrote a plugin that creates a folder in SharePoint. It works just fine. However, I need to be able to use the quotenumber as the folder name. I am having problems figuring out how to retrieve that value. I am able to retrieve values of other fields, but the quote number is assigned when the record is saved. I am guessing that the quote number is not getting assigned until after the plugin is being called. I am not sure what to do. Any ideas?”

So i thought of trying it out. I created a Post Create plugin (synchronous) against quote entity. Than wrote code to retrieve the value for quotenumber from the inputparameters property bag. As it was create event i thought the value must be there for it. However i saw that the quotenumber property is not being passed as a part of inputparameters.

So than I used ForceSubmit method to get its value. However this time i was getting blank value. Than tried by registering the post entity image, but was still getting the blank value.

Finally i tried by registering the plugin in child pipeline, and to my surprise the value was there for the quotenumber attribute.

So to get the quotenumber we need to register our plugin in post create and childpipeline. ( no need of ForceSubmit method or PostEntityImage)

I hope it helps !

 

Bye.

LINQ to Microsoft Dynamics CRM


Suppose this is our entity’s schema name “new_test

and it contains following fields

new_name

new_lastname

Using CrmSvcUtil  we have created the Entities classes and Data Context class.

https://nishantrana.wordpress.com/2010/08/11/using-crmsvcutil/

Now this is how we could use LINQ to query data using query expression as well as method based query.

Create the instace of DataContext class named xrm

var myXrm = new xrm(“CRMOnPremise”);

To loop through all the test records


foreach (var testRecord in myXrm.new_tests)
{
// print the information
}

To select a specific record


var singleRecord = (from myTest in myXrm.new_tests
where myTest.new_lastname == “Rana”
select myTest).Single();

var singleRecord1 = myXrm.new_tests
.Single(t => t.new_lastname == “Rana”);

To select all the records having last name as Rana

var allRecord = from myTest in myXrm.new_tests
where myTest.new_lastname == “Rana”
select myTest;

var allRecords1 = myXrm.new_tests.
Where(t => t.new_lastname == “Rana”);

To order the records

var allRecOrder=from myTest in myXrm.new_tests
orderby myTest.new_name  ascending
where myTest.new_lastname==“Rana”
select myTest;

var allRecOrder1 = myXrm.new_tests
.OrderBy(t => t.new_name)
.Where(t => t.new_lastname == “Rana”);

To select  specific field instead of the entire record


var singleField = from myTest in myXrm.new_tests
select myTest.new_name;

var singleField1 = myXrm.new_tests
.Select(t => t.new_name);

To return specific fields

var specificFields = from myTest in myXrm.new_tests
select new { myTest.createdby, myTest.createdon };

var specificFields1 = myXrm.new_tests
.Select(t => new { t.createdby, t.createdon });

Use of Take and Skip function
Take returns the given number of elements and ignores the rest
Skip skips the given number of elements and yielding the rest

var takeField = (from myTest in myXrm.new_tests
select myTest.new_name).Take(2);

var takeField1 = myXrm.new_tests
.Take(2)
.Select(t => t.new_name);

var skipField = (from myTest in myXrm.new_tests
select myTest.new_name).Skip(2);

var skipField1 = myXrm.new_tests
.Skip(2)
.Select(t => t.new_name);

Join – similar to inner join
The ‘select’ and ‘orderBy’ calls may only reference

a single common entity type.
We will get above error if we try to retrieve value from  the other entity involved in join
var joinRecords = from t in myXrm.new_tests
join s in myXrm.systemusers on
t.ownerid.Value equals s.systemuserid
select new {t.new_name  };

var joinRecords1=myXrm.new_tests
.Join(myXrm.systemusers,
t=>t.ownerid.Value,
s=>s.systemuserid ,
(t,s)=>new {t.new_name});

Where conditions with Contains,StartsWith, EndsWith and

Equal string functions

var test1 = from p in myXrm.new_tests
where p.new_name.Contains(“R”)
select p;
var test2 = from p in myXrm.new_tests
where p.new_name.StartsWith(“R”)
select p;
var test3= from p in myXrm.new_tests
where p.new_name.EndsWith(“D”)
select p;

var test11 = myXrm.new_tests
.Where(t => t.new_name.Contains(“R”));
var test22 = myXrm.new_tests
.Where(t => t.new_name.StartsWith(“R”));
var test32 = myXrm.new_tests
.Where(t => t.new_name.EndsWith(“D”));

Download the project :-

http://www.box.net/shared/xbg0xd5p7m

Bye..

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.

CrmService in CRM 3.0 and CRM 4.0.


Suppose we have a custom entity named Test

having

Name, First Name and Last Name as varchar field.

And Picklist field called Hobby with default value as Music.

If we are creating a new record for this entity using CrmService from an external application, by only specifying value of First Name field.

It would create the record for us, however the value for Hobby picklist field would be null (it won’t consider the default value set for it)

mf1CRM3

However if we create the same record in CRM 4.0 either by using CrmService’s 3.0 end point or 4.0 end point, in both the cases the value for Hobby field would be set to Music, even though we hadn’t specified any value for it while creating the record.

mf1

CRM 4.0 does take in to account the default value set for the fields. So the records created would have proper default value set for those fields even if no value has been assigned to them, while creating the record.

Bye..

Information on Microsoft Dynamics CRM 2011 (CRM 5.0)


Hi,

Check out this wonderful post

http://www.crmdynamics.net/microsoft-crm-product-information-pricing-faq/

Bye..