Fetching the selected records in a grid

Make sure that you read this page if you want to use the selected values in a grid:
http://msdn2.microsoft.com/en-us/library/bb267367.aspx

Until some time ago I was using one of the functions that CRM uses, but since that is unsupported and the method as described in the article as stated above is supported, I am using the new approach.

In short it comes down to this:


// window.dialogArguments contains an array of the IDs for the
// selected records.
var sSelectedRows = window.dialogArguments;

// If sSelectedRows is empty, do not execute the update.
if (sSelectedRows == "" sSelectedRows.length == 0)
{
alert("You must select records in order to use this feature.");
window.close();
}
else
{
//Do something;
}


Happy coding!

10 comments:

Abraham Saldana said...

Yes but I encounter an issue if your code is behind a load balancer and have a different server name, the code will not work propertly, only on a single server implementation.

Abe

Ronald Lemmen said...

Hi Abraham,

An issue doesn't seem logical to me. The code does use the window.dialogArguments. This should be filled anyway, regardless of if it is a single server install or load balanced.

It shouldn't be, but it might be that due to security settings the dialogArguments will not get filled when you are redirecting the user to another server from the button in the toolbar. Did you set the url relative in the isv.config?

Gustaf Westerlund said...

Hi,
I am trying to get this to work, but my window.dialogArguments is just null. I have my aspx-page on another port (i.e. different server) why I believe it might have something to do with security in IE. I have added the url of the aspx to local intranet sites and modified the securitysetting but to no avail. Any ideas?

Gustaf Westerlund

Ronald Lemmen said...

Hi Gustaf,

Try changing the winmode as that appears to be an issue every now and then.

Hope this helps,

Ronald

Gustaf Westerlund said...

Hi,
Well, I actually tried to add a virtual directory bellow the CRM-site, with an html-file with a test javascript and it worked. So, there seems to be some problem with security and IE. I will be using the workaround this time.

Gustaf

Anonymous said...

Hi Robert, your posts always have great value - thanks for publishing them. Have you come across any way to get ALL of the records in a grid, instead of just the selected?

Thanks!

Anonymous said...

Hi Ronald,
I am have few problems getting the GUID's of the records selected in the Grid..I tried the code above mentioned, it did not work
My requirement is
Few records is selected in the Grid of a CASE Entity and button is added on top of the grid, when i click that buton a window should show up the Incident ids f the Selected record ..please help me on thie...

Anonymous said...

Im using CRM 4.0

Vinoth said...

Hi Ronald

Can you share with us the unsupported way (One function the CRM uses) that you was using before this supported way.

Thanks,
Vinoth

Ronald Lemmen said...

Hi Vinoth,

When I created this post, it was mid 2007. I cannot remember now (end 2009) what I used back then..

Kind regards,
Ronald