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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to display list of employee mapped to account in lookup using javascript

(0) ShareShare
ReportReport
Posted on by 242

Hi,

i created a custom entity Employee which is having lookup with account so i want to show list of employee mapped with current  account  in employee lookup which is there in account form when clicking on lookup icons i tried with this code  but want to get current id and needs to add in fetchxml don't know how to do that and its not working.

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

    });
}
function addLookupFilter() {
	var getcurrentid=xrm.page.data.entity.getId();
    var fetchXml = '<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false"><entity name="new_employee"><attribute name="new_employeeid" /><attribute name="new_name" /><attribute name="createdon" /><order attribute="new_name" descending="false" /><filter type="and"><condition attribute="new_accounteid" operator="eq" uiname="A Datum Corporation" uitype="account" value="{A16B3F4B-1BE7-E611-8101-E0071B6AF231}" /></filter></entity></fetch>';
    Xrm.Page.getControl("new_employeeaccountid").addCustomFilter(fetchXml);
}


*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Radu Chiribelea Profile Picture
    6,667 on at

    Hello,

    If i understood correctly, sounds like you could achieve the same result with filtered lookups - without needing to write custom code.

    Please see this blog article for more details: community.dynamics.com/.../how-to-filter-lookups-by-related-records-in-dynamics-365

    Regards,

    Radu

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi ,

    You don't need to add complete fetch xml,  only filter you have to add. I have corrected your below method -

    Try with this -

    function addLookupFilter() {

    var getcurrentid=xrm.page.data.entity.getId();

               var filter = "<filter type='and'>" +

                                       "<condition attribute='new_accounteid' operator='eq' value='"+getcurrentid+"' />" +

                                 "</filter>";

               Xrm.Page.getControl("new_employeeaccountid").addCustomFilter(filter);

     }

    You can refer below reference-

    community.dynamics.com/.../278632

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans