Showing posts with label Guid. Show all posts
Showing posts with label Guid. Show all posts

Sunday, July 29, 2012

How to get all the selected records id for the bulk edit form

Further to one of our previous blog spot

We can write scripts on bulk edit form to check that the entered field value is unique for the selected group of records. If the value is duplicate then the user should get an alert and the bulk edit form should be closed.

To achieve this, we need to retrieve all the records and compare the new value with the existing values.

But to retrieve we require the ids of all the selected records for bulk edit. To get ID we normally use

Xrm.Page.data.entity.getId()

But this will not give us the id of all the selected records. To get ids of all selected records we need to use a window command window.dialogArguments.

 //check whether the form is bulk edit form

 var formType = Xrm.Page.ui.getFormType();

if (formType == 6)
{

 //Read ids from dialog arguments

 var records = window.dialogArguments;

 for(i=0; i<records.lenght;i++)
 {
   alert(records[i]);
 }
}

Hope this helps and is useful!!

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>

</Button>

</Buttons></MenuBar></Grid></Entity>

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();
xmlDoc.LoadXml(recordIds);
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.