Thursday, September 24, 2009

How to read the record selection from the ISV buttons added to the Grid

The buttons added to the CRM grids allow the user to select multiple records from the Grid and perform the said operation on all the selected records.

It is very easy to add a button on an entity grid. You need to add the button tag to the Grid section as explained below. It is important that for the selected record information to be passed on to the receiving page, the page should be displayed in a Modal window. Hence the Winmode for the button should be “2”

<Entity name="account"><Grid><MenuBar><Buttons>

<Button Icon="/_imgs/ico_18_debug.gif" Url="/ISV/test.htm" WinMode="2">

<Titles><Title LCID="1033" Text="Get GUIDS" /></Titles>

<ToolTips><ToolTip LCID="1033" Text="Get GUIDS for selected records" /></ToolTips>



Now, we need to be able to read the record selection from the grid on the custom page. The record selection is passed to the receiving page as a comma separated list of entityid’s of the selected records from the grid. This is enclosed in the <record></record> tags.

If you want to read the information through server-side code you can read it using Request.InputStream.

StreamReader sr = new StreamReader(Request.InputStream);
string recordIds = sr.ReadToEnd();

Since it is enclosed in <record> tag it can be read as XML string
XmlDocument xmlDoc = new XmlDocument();
selectedEntities = xmlDoc.DocumentElement.InnerText;

and the information then split by comma to extract the list of ids.
return selectedEntities.Split(new char[] { ',' });

If you want to read this information from client side through jscript… you will get the id using window.dialogArguments and then you can perform the same operations as above.

No comments:

Post a Comment