
as per my requirement, on a button click i have to get subgrid rows records. for this functionality i am using below code. but it's not working well.
var allGridEntities = [];
var rows = formContext.getControl("Warranty_Claim_Line_Items").getGrid().getRows();
rows.forEach(function (row, i) {
allGridEntities.push(row.getData().getEntity().attributes);
});
i am getting 0 length of sub grid rows while subgrid has one record. i have put two tab on form, 1. General, 2. Warranty Claim Line, after click on tab "Warranty Claim Line" subgrid be shows then this function works fine.
Please suggest best solution
thanks.
Hi Altaf,
Is your subgrid set in "Warranty Claim Line" tab?
If so, the reason of the issue is that subgrids within tabs are not loaded until the tab is expanded, it's by design in UCI.
There are some solutions as following:
1. Focus to the "Warranty Claim Line" tab by javascript when you want to get total count of "Warranty_Claim_Line_Items",
then wait seconds for the subgrid being fully loaded.
Xrm.Page.ui.tabs.get("Warranty_Claim_Line_TAB").setFocus();
setTimeout(function(){
var total = formContext.getControl("Warranty_Claim_Line_Items").getGrid().getTotalRecordCount();
}, 8000);
2. If method 1 is not friendly to user, you might need to retrieve total count of related records by Xrm.WebApi.retrieveMultipleRecords function directly.
Please take introduction below as reference:(subgrid is not mentioned in the article, but it's similar to web resources.)
Regards,
Clofly