fetchxml linked-entity with lookup filter

Hello, In this article i will share with you how to add a lookup filter to a linked entity with Fetchxml

In the serviceappointment entity ,  i added  a lookup  field “new_contract”  to diplay the list of contract,
 so i want to display the list of contract of the selected account.

i create a fetchxml filter and i added it to javascript function :

function preFilterLookup() {
Xrm.Page.getControl("new_contrat").addPreSearch(function () {
addLookupFilter();


});
}
function getlookupCustomer()
{
var lookupObject = Xrm.Page.getAttribute("customers");

if (lookupObject != null) {

var lookUpObjectValue = lookupObject.getValue();

if ((lookUpObjectValue != null)) {

var lookuptextvalue = lookUpObjectValue[0].id;
return lookuptextvalue;

}
}
}
function addLookupFilter() {
var customer = getlookupCustomer();

if (customer != null) {

fetchXml = ""
+ " "
+ "";
Xrm.Page.getControl("new_contrat").addCustomFilter(fetchXml);
}
}

Advertisements