Archive
Updating selected records in the contact Grid – CRM 2011
Hi,
In CRM 2011, we can update selected records in the Grid using Ribbon customizations (i.e., by using a Custom Ribbon Button).
Steps:-
- Create a new Solution called “Ribboncustomer” and add ‘contact’ entity and a newly created web resource called ”ribbon.js” with below function
function processrecords(selectedIds) {
if (selectedIds != null && selectedIds != “”) {
var strIds = selectedIds.toString();
var arrIds = strIds.split(“,”);
for (var indxIds = 0; indxIds < arrIds.length; indxIds++) {
updateRecords(arrIds[indxIds]);
}
}
else {
alert(“No records selected!!!”);
}
}
function updateRecords(contactId) {
//Use OData or Soap call to update the record using passed GUID
}
- Publish the customizations
- Export the Solutions and Save
- Unzip the Solution and Open the “customizations.xml” using VS 2010.
- search for <RibbonDiffXML> node
- Replace with below node
<RibbonDiffXml>
<CustomActions>
<CustomActionId=“Sample.Grid.contact.CustomTab.CustomAction“Location=“Mscrm.Tabs._children“Sequence=“40“>
<CommandUIDefinition>
<TabId=“Sample.Grid.contact.CustomTab“Command=“Sample.Grid.contact.CustomTab“
Title=“$LocLabels:Sample.contact.CustomTab.Title“
Description=“$LocLabels:Sample.contact.CustomTab.Description“Sequence=“500“>
<ScalingId=“Sample.Grid.contact.CustomTab.Scaling“>
<MaxSizeId=“Sample.Grid.contact.CustomTab.FirstGroup.MaxSize“
GroupId=“Sample.Grid.contact.CustomTab.FirstGroup“
Sequence=“10“Size=“LargeMedium“ />
</Scaling>
<GroupsId=“Sample.Grid.contact.CustomTab.Groups“>
<GroupId=“Sample.Grid.contact.CustomTab.FirstGroup“Command=“Sample.Grid.contact.FirstGroup“Sequence=“10“
Title=“$LocLabels:Sample.contact.CustomTab.FirstGroup.Title“Template=“Mscrm.Templates.3.3“>
<ControlsId=“Sample.Grid.contact.CustomTab.FirstGroup.Controls“>
<ButtonId=“Sample.Grid.contact.CustomTab.FirstGroup.FirstButton“
ToolTipTitle=“$LocLabels:Sample.contact.CustomTab.FirstGroup.FirstButton.LabelText“
ToolTipDescription=“$LocLabels:Sample.contact.CustomTab.FirstGroup.FirstButton.ToolTipDescription“
Command=“Sample.Grid.contact.FirstButton“Sequence=“10“ LabelText=“$LocLabels:Sample.contact.CustomTab.FirstGroup.FirstButton.LabelText
“Alt=“$LocLabels:Sample.contact.CustomTab.FirstGroup.FirstButton.LabelText“
Image16by16=“/_imgs/ribbon/AddEmail_16.png“Image32by32=“/_imgs/ribbon/Email_32.png“TemplateAlias=“o1“ />
</Controls>
</Group>
</Groups>
</Tab>
</CommandUIDefinition>
</CustomAction>
</CustomActions>
<Templates>
<RibbonTemplatesId=“Mscrm.Templates“></RibbonTemplates>
</Templates>
<CommandDefinitions>
<CommandDefinitionId=“Sample.Grid.contact.CustomTab“>
<EnableRules>
<EnableRuleId=“Mscrm.Enabled “ />
</EnableRules>
<DisplayRules>
<DisplayRuleId=“Mscrm.CanWriteContact“ />
</DisplayRules>
<Actions/>
</CommandDefinition>
<CommandDefinitionId=“Sample.Grid.contact.FirstGroup“>
<EnableRules>
<EnableRuleId=“Mscrm.Enabled “ />
</EnableRules>
<DisplayRules>
<DisplayRuleId=“Mscrm.CanWriteContact“ />
</DisplayRules>
<Actions />
</CommandDefinition>
<CommandDefinitionId=“Sample.Grid.contact.FirstButton“>
<EnableRules/>
<DisplayRules/>
<Actions>
<JavaScriptFunctionLibrary=“$webresource:new_ShowMessage“FunctionName=“processrecords“>
<CrmParameterValue=“SelectedControlSelectedItemIds“ />
</JavaScriptFunction>
</Actions>
</CommandDefinition>
</CommandDefinitions>
<RuleDefinitions>
<TabDisplayRules>
<TabDisplayRuleTabCommand=“Sample.Grid.contact.CustomTab“>
<EntityRuleEntityName=“contact“Context=“HomePageGrid“ />
</TabDisplayRule>
</TabDisplayRules>
<DisplayRules />
<EnableRules />
</RuleDefinitions>
<LocLabels>
<LocLabelId=“Sample.contact.CustomTab.FirstGroup.FirstButton.LabelText“>
<Titles>
<Titlelanguagecode=“1033“description=“Update Records“ />
</Titles>
</LocLabel>
<LocLabelId=“Sample.contact.CustomTab.Description“>
<Titles>
<Titlelanguagecode=“1033“description=“A custom tab for the Contact entity.“ />
</Titles>
</LocLabel>
<LocLabelId=“Sample.contact.CustomTab.FirstGroup.Title“>
<Titles>
<Titlelanguagecode=“1033“description=“Get IDs Group“ />
</Titles>
</LocLabel>
<LocLabelId=“Sample.contact.CustomTab.FirstGroup.FirstButton.ToolTipDescription“>
<Titles>
<Titlelanguagecode=“1033“description=“Get the selected GUID’s of Grid items“ />
</Titles>
</LocLabel>
<LocLabelId=“Sample.contact.CustomTab.Title“>
<Titles>
<Titlelanguagecode=“1033“description=“Custom Tab“ />
</Titles>
</LocLabel>
</LocLabels>
</RibbonDiffXml>
The key node in the above XML is <CrmParameterValue=”SelectedControlSelectedItemIds” />
<CommandDefinitionId=“Sample.Grid.contact.FirstButton“>
<EnableRules/>
<DisplayRules/>
<Actions>
<JavaScriptFunctionLibrary=“$webresource:new_ShowMessage“FunctionName=“processrecords“>
<CrmParameterValue=“SelectedControlSelectedItemIds“ />
</JavaScriptFunction>
</Actions>
</CommandDefinition>
We are passing “SelectedControlSelectedItemIds” (i.e.,Selected record Guid’s) to the JScript function. Multiple Id’s seperate by ‘,’.
- We are done with customization part, zip the files and Import the solution & publish all customizations.
- Clear the cache and refresh the browser and you will get the custom tab with “Update Records” button.
** Below are few more key <CrmParameterValue> that can be passed as parameter **
SelectedEntityTypeCode : A number representing the unique type of entity for a record selected in a grid. The Entity type code will vary
between deployments.
SelectedEntityTypeName : A string representing the unique name of the entity for a record selected in a grid.
FirstSelectedItemId : Provides one GUID identifier as a string for the first item selected in a grid.
SelectedControlSelectedItemCount : The number of selected items in a grid.SelectedControlSelectedItemIds : A string array of GUID Id values for all selected items in a grid.
SelectedControlAllItemCount : A string array of GUID Id values for all selected items in a grid.
SelectedControlAllItemIds : A string array providing the GUID Id values for all items displayed in a grid.
SelectedControlUnselectedItemCount : The number of unselected items in a grid.
SelectedControlUnselectedItemIds : A string array of GUID Id values for all unselected items in a grid.
Hope it helps 🙂