Text Scroll

You must welcome, Thank you for visiting my blog.

Search This Blog

Monday, July 6, 2020

Custom Filer with custom field values for filter records in SubGrid for ms crm

function filter_SubGrid() {
debugger ;
try{
var Grid = window.parent.document.getElementById("subgridName"); //grid to filter
if (Grid == null) { //make sure the grid has loaded
    setTimeout(function () {
        filterEquipmentSubGrid();
    }, 2000); //if the grid hasn’t loaded run this again when it has
    return;
}

var SerialNoValue = Xrm.Page.getAttribute("new_serialno").getValue();      //filter by Serial Number
var ProductType = Xrm.Page.getAttribute("new_producttype").getValue();  //filter by Product Type
var ProjectName = Xrm.Page.getAttribute("new_projectname").getValue(); //filter by Project Name
var PlantName = Xrm.Page.getAttribute("new_plantname").getValue();      //filter by Plant Name

//Serial Number
if (SerialNoValue != null) {    
SerialNoValue = SerialNoValue;
}
else{
SerialNoValue = ""; //if filter field is null display nothing
}

//Product Type
if (ProductType != null) {    
ProductType = ProductType;
}
else{
ProductType = ""; //if filter field is null display nothing
}

//Project Name
if (ProjectName != null) {    
ProjectName = ProjectName;
}
else{
ProjectName = ""; //if filter field is null display nothing
}

//Plant Name
if (PlantName != null) {    
PlantName = PlantName;
}
else{
PlantName = ""; //if filter field is null display nothing
}

//fetch xml code which will retrieve all the accounts related to the contact
var fetchXml  = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>";
fetchXml += "<entity name='new_entity'>";
    fetchXml += "<attribute name='new_optionalinformation' />";
    fetchXml += "<attribute name='new_serialnumber' />";
    fetchXml += "<attribute name='new_project' />";
    fetchXml += "<attribute name='new_ponumber' />";
    fetchXml += "<attribute name='new_podate' />";
    fetchXml += "<attribute name='new_invoicedate' />";
    fetchXml += "<attribute name='new_dispatchdate' />";
    fetchXml += "<attribute name='new_customersite' />";
    fetchXml += "<attribute name='new_commissioningstatus' />";
    fetchXml += "<attribute name='new_commissioningdate' />";
    fetchXml += "<attribute name='new_application' />";
    fetchXml += "<attribute name='ownerid' />";
    fetchXml += "<attribute name='new_model_value' />";
    fetchXml += "<attribute name='new_framesize_value' />";
    fetchXml += "<attribute name='new_firmware_value' />";
    fetchXml += "<attribute name='new_producttypevalue' />";
    fetchXml += "<attribute name='new_commissioninglead_name' />";
    fetchXml += "<attribute name='new_serv_equipmentid' />";
    fetchXml += "<order attribute='new_customersite' descending='false' />";
  fetchXml += "<filter type='or'>";    
  fetchXml += "<condition attribute='new_serialnumber' operator='like' value='"+SerialNoValue+"' />";
  fetchXml += "<condition attribute='new_producttypevalue' operator='like' value='"+ProductType+"' />";
  fetchXml += "<condition attribute='new_projectname' operator='like' value='"+ProjectName+"' />";
   fetchXml += "<condition attribute='new_customersitename' operator='like' value='"+PlantName+"' />";
   fetchXml += "</filter>";
   fetchXml += "</entity>";
   fetchXml += "</fetch>";
if (Grid.control != null) {
        Grid.control.SetParameter("fetchXml", fetchXml); //set the fetch xml to the sub grid
Grid.control.refresh(); //refresh the sub grid using the new fetch xml
    }
    else {
        setTimeout('filterSubGrid()', 500);
    }
}
catch(err)
{
alert(err.message);
}
}

No comments:

Post a Comment