Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested answer

Retrieve child record based on the selected parent record.

(0) ShareShare
ReportReport
Posted on by 25

Hi All.

I want to retrieve child data based on the selected parent record for the below scenario. I am using Dynamics 365.

On a custom entity for example entity 'A', I have two lookup field for entity 'B'  and entity 'C', where entity 'B' is a custom entity and entity 'C' is out of box entity and Entity 'B' and entity 'C' having relationship as 1:N.

if 'B' record is selected on the entity 'A' form  then it should display the related records of 'C'  and if no 'B' record is selected then there should be no records shown  for 'C"

Can anybody have a suggestion on this .

Regards,

Richa

  • Richa kumari Profile Picture
    25 on at
    RE: Retrieve child record based on the selected parent record.

    Hi Bipin,

    Thank you very much  for your reply.

    Let me implement this and revert back.

    Regards

    Richa

  • Suggested answer
    Bipin D365 Profile Picture
    28,981 Moderator on at
    RE: Retrieve child record based on the selected parent record.

    Hi,

    I have written the code for you -

    function setParentAccountIdFilter(executionContext) {

    // get the form context
    formContext = executionContext.getFormContext();
    formContext.getControl("msft_company").addPreSearch(function (){
    // get Entity 'B' Lookup field value
    var contact = formContext.getAttribute("msft_emergencycontact").getValue();
    var contactId="{00000000-0000-0000-0000-000000000000}";
    var contactName="Dummy Contact";
    if(contact!=null)
    {
    contactId=contact[0].id;
    contactName=contact[0].name;
    }
    var fetchQuery = "<filter type='and'><condition attribute='primarycontactid' operator='eq' uiname='" + contactName + "' uitype='contact' value='" + contactId + "' /></filter>";

    formContext.getControl("msft_company").addCustomFilter(fetchQuery,"account");
    });
    }

    msft_emergencycontact -> Entity B Lookup field schema name

    msft_company -> Entity C lookup field schema name

    account -> Entity C Name

    contact -> Entity B Name

    primarycontactid -> Entity B lookup field on Entity C

    Please mark my answer verified if this is helpful!

    Regards,

    Bipin Kumar

    Follow my Blog: xrmdynamicscrm.wordpress.com/

  • Richa kumari Profile Picture
    25 on at
    RE: Retrieve child record based on the selected parent record.

    Hi Bipin,

    Thanku for your Reply.

    As i am not very experienced with coding in CRM so will you mind if i ask you to elaborate more on this.

    Thanks in Advance!

    Regards,

    Richa

  • Suggested answer
    Bipin D365 Profile Picture
    28,981 Moderator on at
    RE: Retrieve child record based on the selected parent record.

    Hi,

    Okay. In that case you can use Addcustomfilter client api to achieve your requirement -

    carldesouza.com/.../

    So in fetch xml condition you will add {00000000-0000-0000-0000-000000000000} guid if B is not select and if B is selected the you will pass in the selected record guid.

    blog.magnetismsolutions.com/.../lookup-filtering-using-addcustomfilter-vs-addcustomview-in-dynamics-365

    Please mark my answer verified if this is helpful!

    Regards,

    Bipin Kumar

    Follow my Blog: xrmdynamicscrm.wordpress.com/

  • Richa kumari Profile Picture
    25 on at
    RE: Retrieve child record based on the selected parent record.

    Hi Bipin,

    Yes entity 'c' has a lookup for entity 'b' but the requirement is to show no records for 'b' if user doesn't select  any 'c' record at first. This i want to achieve it through JS.

    Thank you!

    Regards,

    Richa

  • empath-e CRM Profile Picture
    1,136 on at
    RE: Retrieve child record based on the selected parent record.

    Hi Richa,

    Are you referring to something like this where Category only displays lookup values from the associated Area entity and the Issue lookup only display values linked to the value selected in Category?

  • Suggested answer
    Bipin D365 Profile Picture
    28,981 Moderator on at
    RE: Retrieve child record based on the selected parent record.

    Hi,

    Does Entity 'C' has lookup of Entity 'B'. If yes then you can achieve your filtering with OOB related record configuration-

    www.marksgroup.net/.../

    Please mark my answer verified if this is helpful!

    Regards,

    Bipin Kumar

    Follow my Blog: xrmdynamicscrm.wordpress.com/

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

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Holly Huffman Profile Picture

Holly Huffman 103

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 96 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 51 Most Valuable Professional

Product updates

Dynamics 365 release plans