A common requirement is to pass poarameters to a JavaScript function called when clicking a Ribbon button.
To pass parameters regarding a grid or a subgrid we can use the "crmparameter" element of the RibbonDiffXml file.
The available parameters can be devided in three groups:
- Selected items
- SelectedControlSelectedItemCount: The number of selected items in a grid or subgrid.
- SelectedControlSelectedItemIds: A string array of GUID Id values for all selected items in a grid.
- SelectedControlSelectedItemReferences: An array of EntityReference objects that represent all the selected items in the grid
- All items
- SelectedControlAllItemCount: The number of items in a grid or subgrid.
- SelectedControlAllItemIds: A string array of GUID Id values for all items in a grid.
- SelectedControlAllItemReferences: An array of EntityReference objects that represent all the items in the grid.
- Unselected items
- SelectedControlUnselectedItemCount: The number of unselected items in a grid or subgrid.
- SelectedControlUnselectedItemIds: A string array of GUID Id values for all unselected items in a grid.
- SelectedControlUnselectedItemReferences: An array of EntityReference objects that represent all the unselected items in the grid.
<CommandDefinition Id="Mscrm.SubGrid.opportunity.Command">
<EnableRules>
<EnableRule Id="Mscrm.SubGrid.opportunity.EnableRule"></EnableRule>
</EnableRules>
<DisplayRules></DisplayRules>
<Actions>
<JavaScriptFunction Library="$webresource:functions.js" FunctionName="MyFunction" >
<CrmParameter Value="SelectedControlSelectedItemIds" />
<CrmParameter Value="SelectedControlSelectedItemCount" />
</JavaScriptFunction>
</Actions>
</CommandDefinition>
To access these parameters add them to your function definition like below:
function MyFunction(SelectedControlSelectedItemIds, SelectedControlSelectedItemCount) {
for (i = 0; i < SelectedControlSelectedItemCount; i++) {
}
}
So as you can see it is possible to access records displayed in a subgrid using supported code, so don't get tempted to use document.getElementById. ;)
I hope this help.












