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)

How to retrieve the data based on a lookup using javascript

(0) ShareShare
ReportReport
Posted on by

hi guys,

i have three related entities, let city, bus, booking..

in booking entity if i select a particular city in city lookup i should get the related buses in the buses lookup field..

how to write the code  in javascript..

thanks in advance..

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Rajkumar Rajaraman Profile Picture
    on at
  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi Varun ,

    You can write fetch xml .Here is the sample fetch XML how to  retrieve related record .

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
      <entity name="new_postalcode">
        <attribute name="new_postalcodeid" />
        <attribute name="new_name" />
        <attribute name="createdon" />
        <order attribute="new_name" descending="false" />
        <link-entity name="etel_country" from="etel_countryid" to="optnc_pcountry" alias="ac">
     <attribute name="countryname" />
          <filter type="and">
            <condition attribute="new_countryid" operator="eq" uiname="NOUVELLE-CALEDONIE" uitype="new_country" value="{2CF9EBD6-0575-E611-80E3-0050560111FF}" />
          </filter>
          <link-entity name="new_city" from="new_countryid" to="new_countryid" alias="ad">
         <attribute name="cityname" />
            <filter type="and">
              <condition attribute="new_cityid" operator="eq" uiname="NOUMEA" uitype="new_city" value="{381B1F7C-404F-E711-8103-000C29CBC14A}" />
            </filter>
          </link-entity>
        </link-entity>
      </entity>
    </fetch>


    You can  use web api  to execute fetchXML.

    www.inogic.com/.../execute-fetchxml-using-web-api-in-dynamics-crm-2016

  • Verified answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi Varun,

    If you have set up the relationship between these entities then you can look for the oob related record filtering functionality.

    community.dynamics.com/.../how-to-filter-lookups-by-related-records-in-dynamics-365

    www.powerobjects.com/.../how-to-use-dependent-lookups-for-dynamics-crm-201320152016

    If the above doesn't work then you can add a java script to filter the lookup accordingly-

    www.inogic.com/.../apply-custom-filter-on-lookup-field-in-dynamic-crm-using-script

    Hope this helps.

  • Verified answer
    Community Member Profile Picture
    on at

    Hi,

    You can use add “addPreSearch()“ method. You can read article www.inogic.com/.../apply-custom-filter-on-lookup-field-in-dynamic-crm-using-script

    Hope it helps:)

    Thank You

  • Community Member Profile Picture
    on at

    Hi ridhima, i written the same one but it is throwing an error "is not defined at eval"..

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi Varun,

    The error "is not defined at eval" generally pccurs if there is any syntax error in the javascript or due to cache.

    Do save publish customization, and refresh the form.

    If that doesnt fix the issue then check if there are any javascript syntax error.

    Hope this helps

  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at

    Not sure why you are writing code if this can be done through simple configuration only. refer above suggestion to implement dependent lookup.

  • Suggested answer
    Arpit Shrivastava Profile Picture
    7,518 User Group Leader on at

    Hi Varun,

    You don't need to write a code in order to filter lookup unless filtering of records is complex.

    Go with article suggested by Ravi or cab check below article:

    https://community.dynamics.com/crm/b/magnetismsolutionscrmblog/archive/2017/10/19/how-to-filter-lookups-by-related-records-in-dynamics-365

    https://community.dynamics.com/crm/f/117/t/224515

    If found useful, please mark the answer as verified.


    Cheers
    Arpit
    https://arpitmscrmhunt.blogspot.com

  • Suggested answer
    Preeti Sharma Profile Picture
    2,678 on at

    Hi Varun,

    As suggested above you should use options provided OOB by CRM to filter records based on another lookup on form level.

    Thanks:)

  • Community Member Profile Picture
    on at

    Thank you guys for ur help.. i got my result..

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