I want to get list of all records that are in a subgrid in a form
Is there a way to get it using some api call or using javascript? The below code will fetch the rows if the subgrid is available in the form but I don't want to have the subgrid in the form where I am going to fetch these records
var selectedRows = Xrm.Page.getControl("Contacts").getGrid().getSelectedRows();
var rows = Xrm.Page.getControl("Contacts").getGrid().getRows();
For example, assume that I have a medicalCase entity form, where I am having patients subgrid. I want to get the list of records in the patients subgrid using webapi in some other entity form
Yes, you can retrieve records using fetch.
Use a library like the xrmservicetoolkit to execute your fetch statement.
var fetchXml =
"<fetch mapping='logical'>" +
"<entity name='contact'>" +
"<attribute name='contactid' />" +
"<attribute name='firstname' />" +
"<attribute name='lastname' />" +
"<attribute name='accountrolecode' />" +
"<filter>" +
"<condition attribute='contactid' operator='eq' value='" + contactId + "' />" +
"</filter>" +
"</entity>" +
"</fetch>";
var retrievedContacts = XrmServiceToolkit.Soap.Fetch(fetchXml);
console.log(retrievedContacts[0].attributes['lastname'].value)
See this page for more info.