Answered by:
how to get subgrid record in crm 2013 by using javascript

Question
-
Hi,
I want to count subgrid record in crm 2013 by using javascript. Please tell me how is it possible
Monday, March 31, 2014 6:07 AM
Answers
-
Hello Aamir,
It may be loading issue try below code
function FindControl() {
if (document.getElementById('subgridName')!= null) {
var count=document.getElementById('subgridName').control.get_totalRecordCount();
alert(count);
}
else {
setTimeout("FindControl()", 1000);
}
}
Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.- Edited by HIMBAPModerator Tuesday, April 1, 2014 8:15 AM
- Marked as answer by Aamir Hijazi Tuesday, April 1, 2014 8:20 AM
Tuesday, April 1, 2014 8:14 AMModerator
All replies
-
Hello,
Did you check this
Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.Monday, March 31, 2014 6:49 AMModerator -
Yes I checked this but it is not working in crm 2013Monday, March 31, 2014 6:53 AM
-
Actually there is not supported way to interact with subgrids, so to make it work with ms crm 2013 you might need to do some changes.
Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.Monday, March 31, 2014 7:03 AMModerator -
Hi try this Line .. I have checked it on Account and Contact form ...
Xrm.Page.ui.controls.get('Contacts').$Y_0.get_totalRecordCount()
Zafar Khan
Monday, March 31, 2014 12:13 PM -
Hello Zafar,
Xrm.Page.ui.controls.get('Contacts').$Y_0.get_totalRecordCount()
what is $Y_0?
Monday, March 31, 2014 1:44 PM -
Hi Aamir,
$Y_0 is probably the dynamically generated object name that contains the get_totalRecordCount() method. While this might work, a single rollup can mess it all up if the object name changes. This is a highly unsupported and risky customization in my opinion.
Monday, March 31, 2014 4:47 PM -
HI
AS Dynamotion said , these are unsupported .
U can try
document.getElementById('Contacts').control.get_totalRecordCount()
Zafar Khan
Tuesday, April 1, 2014 7:00 AM -
Hi Zafar,
I tried this but it is not working in crm 2013
var count=document.getElementById('subgridName').control.get_totalRecordCount();
alert(count);
Tuesday, April 1, 2014 7:09 AM -
Hello Aamir,
It may be loading issue try below code
function FindControl() {
if (document.getElementById('subgridName')!= null) {
var count=document.getElementById('subgridName').control.get_totalRecordCount();
alert(count);
}
else {
setTimeout("FindControl()", 1000);
}
}
Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.- Edited by HIMBAPModerator Tuesday, April 1, 2014 8:15 AM
- Marked as answer by Aamir Hijazi Tuesday, April 1, 2014 8:20 AM
Tuesday, April 1, 2014 8:14 AMModerator -
document.getElementById() this is DOM property. And DOM property does not support in dynamic CRM 2013/15
Rajnikant
Thursday, February 26, 2015 11:29 AM -
Hi Zafar,
$Y_0 this is undefined property or null reference. How did you use?
Rajnikant
Thursday, February 26, 2015 11:33 AM -
I would say the support for this is 98%.. the only thing that could mess it up is the function name "get_recordCount" changes...
I have made this so that it can find the object the get_recordCount function is defined in and return the count. so it could be in '$Y_0', '$d_0', '$s_0'.. does not matter.
var ctrl = Xrm.Page.getControl("SubGridName");
for(prop in ctrl)
{
if(typeof ctrl[prop].get_recordCount === 'function')
{
alert(ctrl[prop].get_recordCount());
break;
}
}Please let me know if this does not work for you.. so I can work on for other scenarios.
Ramu
Wednesday, April 22, 2015 7:19 PM -
-
Hi Aamir Hijazi
you can use below code to get sub grid control and number of records in sub grid
function allRecords() {
var allGridRowData = [];
var rows = Xrm.Page.getControl("Contacts").getGrid().getRows();//Contacts is a Sub Grid name
rows.forEach(function (row, i) {
allGridRowData.push(row.getData());
});
}
Here you can get row count and also you can see data
Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.
Anil kumar Rai
Wednesday, September 23, 2015 10:55 AM