Saturday, February 4, 2012

Add Custom Button, Custom Group and Custom Tab in Custom Entity or system Entity

Here you can find the complete code to add Custom Button, Custom Group and Custom Tab in Custom Entity.

Steps:
1 Export the entity
2 Edit the customizations.xml in Visual Studio editor
3 Copy the below code and replace it with RibbonDiffXml
4 Import and Publish the Solution
5 Test and Verify the Requirements
6 Note: If you required to open intelisense in customizations.xml then
1 go in XML menu in VS
2 click on Schema
3 Click on Add
4 select the path \sdk\schemas of CRM 2011
5 Select Customizationssolution.xsd, ribboncore.xsd, ribbontypes.xsd and ribbonwss.xsd files
6 Click open
7 Now check Intelisense

<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>
<CustomAction Id="Sample.new_test.form.Save.CustomAction" Location="Mscrm.Form.new_test.MainTab.Save.Controls._children" Sequence="80">
<CommandUIDefinition>
<Button Id="Sample.new_test.form.Save.Button" Command="Sample.new_test.form.Save.Command" LabelText="Button" ToolTipTitle="Button ToolTip" ToolTipDescription="Button Description" TemplateAlias="o1" Image16by16="/_imgs/ribbon/AddEmail_16.png" Image32by32="/_imgs/ribbon/Email_32.png" />
</CommandUIDefinition>
</CustomAction>
<CustomAction Id="Mscrm.Form.new_test.CustomGroup.CustomAction" Location="Mscrm.Form.new_test.MainTab.Groups._children" Sequence="81">
<CommandUIDefinition>
<Group Id="Mscrm.Form.new_test.CustomGroup.Group" Command="Mscrm.Form.new_test.CustomGroup.Command" Title="HKG Group" Sequence="11" Template="Mscrm.Templates.3.3">
<Controls Id="Mscrm.Form.new_test.CustomGroup.Controls">
<Button Id="Mscrm.Form.new_test.CustomGroup.Button.HK" Sequence="10" Command="Mscrm.Form.new_test.CustomGroup.Button.HK.Command" LabelText="HK" ToolTipTitle="Button ToolTip(HK)" ToolTipDescription="Button Description(HK)" TemplateAlias="o1" Image16by16="/_imgs/ribbon/AddEmail_16.png" Image32by32="/_imgs/ribbon/Email_32.png" />
</Controls>
</Group>
</CommandUIDefinition>
</CustomAction>
<CustomAction Id="Mscrm.Form.new_test.CustomGroup.MaxSize.CustomAction"
Location="Mscrm.Form.new_test.MainTab.Scaling._children"
Sequence="120">
<CommandUIDefinition>
<MaxSize Id="Mscrm.Form.new_test.CustomGroup.MaxSize"
GroupId="Mscrm.Form.new_test.CustomGroup.Group"
Sequence="21"
Size="LargeLarge" />
</CommandUIDefinition>
</CustomAction>
</CustomActions>
<Templates>
<RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>
</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.FirstButton">
<EnableRules>
<EnableRule Id="Mscrm.Enabled " />
</EnableRules>
<DisplayRules>
<DisplayRule Id="Sample.new_test.form.FormStateNotNew.DisplayRule"></DisplayRule>
</DisplayRules>
<Actions></Actions>
</CommandDefinition>
<CommandDefinition Id="Sample.Form.new_test.FirstGroup">
<EnableRules>
<EnableRule Id="Mscrm.Enabled " />
</EnableRules>
<DisplayRules></DisplayRules>
<Actions />
</CommandDefinition>
<CommandDefinition Id="Sample.new_test.form.Save.Command">
<EnableRules />
<DisplayRules />
<Actions>
<JavaScriptFunction Library="$webresource:new_JS_Common_Library" FunctionName="show">
<StringParameter Value="A" />
</JavaScriptFunction>
</Actions>
</CommandDefinition>
<CommandDefinition Id="Mscrm.Form.new_test.CustomGroup.Button.HK.Command">
<EnableRules />
<DisplayRules />
<Actions>
<Url Address="http://www.google.com" />
</Actions>
</CommandDefinition>
<CommandDefinition Id="Mscrm.Form.new_test.CustomGroup.Command">
<EnableRules>
<EnableRule Id="Mscrm.NotOffline"/>
</EnableRules>
<DisplayRules>
<DisplayRule Id="Mscrm.NotOffline"/>
</DisplayRules>
<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>
<LocLabel Id="Sample.new_test.form.Save.LabelText">
<Titles>
<Title languagecode="1033" description="Custom Button1" />
</Titles>
</LocLabel>
<LocLabel Id="Sample.new_test.form.Save.ToolTip">
<Titles>
<Title languagecode="1033" description="Custom Button1" />
</Titles>
</LocLabel>
</LocLabels>
</RibbonDiffXml>

CRM 2011: Reopen or reactivate a closed task / activity with SDK

Use the following line of code to Reopen the closed task in CRM 2011

// Re-open the Task to update it
SetStateRequest ssr = new SetStateRequest();
ssr.EntityMoniker = t.ToEntityReference();
ssr.State = new OptionSetValue(0);
ssr.Status = new OptionSetValue(2);

SetStateResponse resp1 = (SetStateResponse)xrmConnection.Execute(ssr);


Use the following line of code to close task in CRM 2011
// close the task again.
SetStateRequest Closed = new SetStateRequest();
Closed.EntityMoniker = new EntityReference(t.LogicalName, t.Id);
Closed.State = new OptionSetValue(TaskClosedState);
Closed.Status = new OptionSetValue(TaskClosedStatus);

SetStateResponse resp2 = (SetStateResponse)xrmConnection.Execute(Closed);

CRM 4.0: Reopen or reactivate a closed task / activity with SDK

Once a time Some tasks and opportunities closed wrongly in CRM4.0, so I need to reopen all these tasks and opportunity, to do this you will follow some steps:


Task: loop through for all the selected tasks
foreach (BusinessEntity TaskEntity in result.BusinessEntities)
{
try
{
task objtaskEntity = (task)TaskEntity;
task objtaskEntity1 = (task)TaskEntity;

//Create the request of the Task for State
SetStateTaskRequest objtask = new SetStateTaskRequest();
objtask.EntityId = new Guid(objtaskEntity.activityid.Value.ToString());
objtask.TaskState = 0;
objtask.TaskStatus = 2;
//Execute the request
SetStateTaskResponse res = (SetStateTaskResponse)service.Execute(objtask);


//You need to update the attribute of task entity then use the following line of code
objtaskEntity1.category = string.Empty;
service.Update(objtaskEntity1);
break;
}
catch(Exception ex)
{
continue;
}
}

Opportunity: to update or reopen Opportunity you will follow the following line of code

Picklist plSalesStage = new Picklist();
lSalesStage.Value = 1;
RenOpp.salesstagecode = plSalesStage;

OpportunityStateInfo objstateinfo = new OpportunityStateInfo();
objstateinfo.Value = OpportunityState.Open;
RenOpp.statecode = objstateinfo;
service.Update(RenOpp);

Split the String values with a special character in MS Flow to convert this into Array

 Many times we have a requirement to prepare the Mailing address for some of the documents, suppose there are Address Line1, Address Line2, ...