web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Custom JavaScript for N:N Relationship.

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans