Retrieving Subgrid Items count using Javascipt.
1.Get the subgrid using "Name" of subgrid as given below.
2.Write the Javascript function as given below:
For MS CRM 2013:
function FindControl() {
if (document.getElementById('subgridName')!= null) {
var count=document.getElementById('subgridName').control.get_totalRecordCount();
alert(count);
}
else {
setTimeout("FindControl()", 1000);
}
}
3.Result
Hope this helps,
Regards,
Yusuf
1.Get the subgrid using "Name" of subgrid as given below.
2.Write the Javascript function as given below:
function subgridItemCount() { // Get the Subgrid Control var grid = Xrm.Page.ui.controls.get('LineItems')._control; if (grid.get_innerControl() == null) { setTimeout(subgridItemCount, 1000); return false; } else if (grid.get_innerControl()._element.innerText.search("Loading") != -1) { setTimeout(subgridItemCount, 1000); return false; } var countRec = grid.get_innerControl().get_allRecordIds().length; if (countRec > 0) { alert(countRec); } }
For MS CRM 2013:
function FindControl() {
if (document.getElementById('subgridName')!= null) {
var count=document.getElementById('subgridName').control.get_totalRecordCount();
alert(count);
}
else {
setTimeout("FindControl()", 1000);
}
}
Hope this helps,
Regards,
Yusuf
Unfortunately, this will not work in CRM 2013. Do you have a current solution?
ReplyDeleteI would also be happy if there is a solution for CRM 2013
ReplyDeleteThis code is works fine.Thanks for posting the blog clearly and neatly present it.
ReplyDeleteThis solution can help you for MS CRM 2013.
ReplyDelete(function () {
var TimeOut = 0;
var subGrids = $('#new_myGrid'); //get your gird
if (subGrids.length > 0 && subGrids[0].control.get_totalRecordCount() > -1) {
setCridCounter(subGrids[0]);
}
else {
var intId = setInterval(function () {
subGrids = $('#' + EntityHash[EntityType]);
if (subGrids.length > 0 && subGrids[0].control.get_totalRecordCount() > -1) {
clearInterval(intId);
setCridCounter(subGrids[0]);
}
else if (TimeOut > 5000)
//If not completed by now, exit this interval after 5 sec.
clearInterval(intId);
TimeOut += 500;
}, 500);
}
function setCridCounter(Sgrid) {
var counter = Sgrid.control.get_totalRecordCount();
alert(counter);
}
})();
Correction for the self-execution code above.
ReplyDelete(function () {
var TimeOut = 0;
var subGrids = $('#new_myGrid'); //get your gird
if (subGrids.length > 0 && subGrids[0].control.get_totalRecordCount() > -1) {
setCridCounter(subGrids[0]);
}
else {
var intId = setInterval(function () {
subGrids = $('#new_myGrid');
if (subGrids.length > 0 && subGrids[0].control.get_totalRecordCount() > -1) {
clearInterval(intId);
setCridCounter(subGrids[0]);
}
else if (TimeOut > 5000)
//If not completed by now, exit this interval after 5 sec.
clearInterval(intId);
TimeOut += 500;
}, 500);
}
function setCridCounter(Sgrid) {
var counter = Sgrid.control.get_totalRecordCount();
alert(counter);
}
})();
Thanks for posting! :)
ReplyDeleteThis is very Helpful Thanks again
ReplyDelete