I have written a JS Code for retrieving data from N: N Relationship.
The code is given below:-
var fetchXml = "";
function filterLookup()
{
debugger;
//alert("Filter Lookup");
var checkValue = new Array();
checkValue = Xrm.Page.getAttribute("smp_country").getValue();
alert("Check Value:- " +checkValue[0].name );
// if(Xrm.Page.getControl("smp_country")!=null && Xrm.Page.getControl("smp_country")!= undefined)
if(checkValue[0].name!=null && checkValue[0].name!= undefined)
{
Xrm.Page.getControl("smp_account_type").removePreSearch(PopulateAccountType);
Xrm.Page.getControl("smp_account_type").addPreSearch(PopulateAccountType);
}
else
{
Xrm.Page.getControl("smp_account_type").removePreSearch(PopulateAccountType);
}
}
function PopulateAccountType()
{
debugger;
//if(Xrm.Page.getControl("smp_country")!=null && Xrm.Page.getControl("smp_country")!= undefined)
if(checkValue[0].name!=null && checkValue[0].name!= undefined)
{
var countryID = Xrm.Page.getAttribute("smp_country").getValue();
var countryGUID = countryID [0].id;
alert("GUID :- "+ countryGUID );
SDK.REST.retrieveMultipleRecords("smp_smp_accounttype_smp_country", "$select=smp_accounttypeid&$filter=smp_countryid eq guid'"+countryGUID +"'", retrieveAccountTypes, errorCallBack, retrieveAccountTypesComplete);
Xrm.Page.getControl("smp_account_type").addCustomFilter(fetchXml);
}
}
function retrieveAccountTypesComplete() {
}
function errorCallBack(error)
{
alert(error.message);
}
function retrieveAccountTypes(account_Type)
{
fetchXml = "<filter type='and'><condition attribute='smp_accounttypeid' operator='in'>"
for(var i=0; i<account_Type.length; i++)
{
var filterData = "<value>"+account_Type[i].smp_accounttypeid+"</value>";
fetchXml= fetchXml.concat(filterData );
}
var data = "</condition></filter>"
fetchXml=fetchXml.concat(data);
}
The issue I am Facing that the Filtering of account_type is delaying after second click.
The filtering is not done in the first attempt.
I need help on this.
Thanks in advance.
*This post is locked for comments