Hi Folks,
The Below scenario explains how to filter the Subgrid using a record selected in Lookup.
In this scenario I have a lookup for selecting the courses in Post Graduation. If we select any of the record in lookup, then the corresponding subjects must be displayed in the grid view.
The below screen shot shoes the subgrid name
For creating this we require the FetchXml code, which we can get through Advanced Find in CRM.
The below snippet code can be used to filter the records,
---------------->>
function updateSubGrid() {
var Subjects = document.getElementById("Subjects");
var lookupfield = new Array;
var dept;
lookupfield = Xrm.Page.getAttribute("lookup schema name").getValue();
if (lookupfield != null) {
var lookupid = lookupfield[0].id;
dept=lookupfield[0].name; //I am storing the name of record in "dept" variable
}
else
{
return;
}
if (Subjects ==null || Subjects.readyState != "complete")
{
setTimeout('updateSubGrid()', 2000);
return;
}
var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>";
fetchXml += "<entity name='new_subjects'>";
fetchXml += "<attribute name='new_subjectsid' />";
fetchXml += "<attribute name='new_name' />";
fetchXml += "<attribute name='createdon' />";
fetchXml += "<order attribute='new_name' descending='false' />";
fetchXml += "<filter type='and'>";
fetchXml += "<condition attribute='new_dept' operator='eq' uiname='"+ dept +"' uitype='new_department' value='" + lookupid + "' />"; //dept specifies the name of record and lookupid represents Guid
fetchXml += "</filter>";
fetchXml += "</entity>";
fetchXml += "</fetch>";
Subjects.control.SetParameter("fetchXml", fetchXml);
Subjects.control.refresh();
}
The Below scenario explains how to filter the Subgrid using a record selected in Lookup.
In this scenario I have a lookup for selecting the courses in Post Graduation. If we select any of the record in lookup, then the corresponding subjects must be displayed in the grid view.
The below screen shot shoes the subgrid name
For creating this we require the FetchXml code, which we can get through Advanced Find in CRM.
The below snippet code can be used to filter the records,
---------------->>
function updateSubGrid() {
var Subjects = document.getElementById("Subjects");
var lookupfield = new Array;
var dept;
lookupfield = Xrm.Page.getAttribute("lookup schema name").getValue();
if (lookupfield != null) {
var lookupid = lookupfield[0].id;
dept=lookupfield[0].name; //I am storing the name of record in "dept" variable
}
else
{
return;
}
if (Subjects ==null || Subjects.readyState != "complete")
{
setTimeout('updateSubGrid()', 2000);
return;
}
var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>";
fetchXml += "<entity name='new_subjects'>";
fetchXml += "<attribute name='new_subjectsid' />";
fetchXml += "<attribute name='new_name' />";
fetchXml += "<attribute name='createdon' />";
fetchXml += "<order attribute='new_name' descending='false' />";
fetchXml += "<filter type='and'>";
fetchXml += "<condition attribute='new_dept' operator='eq' uiname='"+ dept +"' uitype='new_department' value='" + lookupid + "' />"; //dept specifies the name of record and lookupid represents Guid
fetchXml += "</filter>";
fetchXml += "</entity>";
fetchXml += "</fetch>";
Subjects.control.SetParameter("fetchXml", fetchXml);
Subjects.control.refresh();
}