Reputation: 121
Lets say I have a Grid in CRM showing me Invoices which need to be created by using a custom javascript dialog. In this dialog I want to put two options which are doing the following:
1) selects all Rows flagged as selected in the Grid
2) selects all existing Rows in the Grid
Particularly I have an issue with No. 2)
I cannot figure out how to get all rows if I have lets say 5 pages of invoices. So how can I select all rows in the Grid and not only those shown on the actual grid page?
Any advice is highly appreciated.
Regards Sandro
Upvotes: 0
Views: 2474
Reputation: 6170
If you want to retrieve only the elements that are selected in a grid, then you can use the Ribbon Workbench to configure a new button on the sub grid. The Button must have a Command Action which can be configured to pass selected items to a JavaScript method using the SelectedControlSelectedItemIds
parameter
There is a SelectedControlAllItemIds
parameter too, but I think this only gives "All Items" in the current page, not all pages. Not sure about these last bits so definitely worth a try
If that doesn't work, then you will have to do this yourself using a WebApi
call. For example, to get all Contacts associated with an Account, you might do something like this:
// Get the ID of the parent account
var accountid = {AccountId};
// Execute a query to retrieve all Contacts associated with the given Account ID
Xrm.WebApi.retrieveMultipleRecords("contacts", "?$select=contactid&$filter=_parentcustomerid_value eq " + accountid)
.then(
function(results) { console.log(results); },
function(error) { console.log(error); }
);
Read more about retrieveMultipleRecords
here
Upvotes: 1