Quantcast
Channel: Microsoft Dynamics AX Forum - Recent Threads
Viewing all articles
Browse latest Browse all 72043

Xrm.Page.getControl() returns null

$
0
0

Using CRM 2015.

I'm creating a button that loops over the selected records in a view and performs a custom method.

Here's the setup:

Created a button on the main view menu bar in one of our custom entities.

Added javascript for the new button to call.

 try {
 var selectedEntityReferences = [];

 var selectedRows = Xrm.Page.getControl("<control name here>").getGrid().getSelectedRows();
 alert("selectedRows:" + selectedRows.getLength());

 selectedRows.forEach(function (selectedRow, i) {

 selectedEntityReferences.push(selectedRow.getData().getEntity().getEntityReference());
 alert(selectedRow.getData().getEntity().id);

 });
 } catch (ee) {
  alert(ee.message);
 }

I tried replacing "<control name here>" with what I thought the name of the control was - but it gives 'selectedRows is null' error.

This sent me on a search to find the proper control name.

In the MSD documentation I found 'Xrm.Page.getControl()' should return a list of controls - but when I use this method it returns a null object.

This leads me to believe there are no controls on the page - but how is this possible?

Also - where would I find the proper name for the control that holds the view grid?


Viewing all articles
Browse latest Browse all 72043

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>