Display Ur Custom View in SubGrid Control using Fetch XML
function updateSubGrid() {
//This will get the grid details and store in a variable.
var relatedProjects = document.getElementById("ProjectHR");
//Initializing the lookup field to store in an array.
var lookupfield = new Array;
//Get the lookup field
lookupfield = Xrm.Page.getAttribute("bis_project01").getValue();
//This will get the lookup field guid if there is value present in the lookup
if (lookupfield != null) {
var lookupid = lookupfield[0].id;
}
//Else the function will return and no code will be executed.
else {
return;
}
//This method is to ensure that grid is loaded before processing.
if (relatedProjects == null || relatedProjects.readyState != "complete") {
//This statement is used to wait for 2 seconds and recall the function until the grid is loaded.
setTimeout('updateSubGrid()', 2000);
return;
}
//This is the fetch xml code which will retrieve all the consultants (resdex) related to the project selected for billing.
var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>";
fetchXml += "<entity name='new_resources'>";
fetchXml += "<attribute name='new_name' />";
fetchXml += "<attribute name='new_expectedctclakhs' />";
fetchXml += "<attribute name='new_currentctc_lakhs' />";
fetchXml += "<attribute name='new_rate' />";
fetchXml += "<attribute name='new_resourcesid' />";
fetchXml += "<order attribute='new_name' descending='false' />";
fetchXml += "<link-entity name='new_projectstatus' from='new_consultant' to='new_resourcesid' alias='aa'>";
fetchXml += "<filter type='and'>";
fetchXml += "<condition attribute='new_exampleprojectid' operator='eq' uitype='opportunity' value='" + lookupid + "' />";
fetchXml += "</filter>";
fetchXml += "</link-entity>";
fetchXml += "</entity>";
fetchXml += "</fetch>";
//Setting the fetch xml to the sub grid.
relatedProjects.control.setParameter("fetchXml", fetchXml);
//This statement will refresh the sub grid after making all modifications.
relatedProjects.control.refresh();
}
No comments:
Post a Comment