Skip to main content

Notifications

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
    Richa kumari 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
    Bipin D365 28,964 Super User 2024 Season 1 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
    Richa kumari 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
    Bipin D365 28,964 Super User 2024 Season 1 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
    Richa kumari 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
    empath-e CRM 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
    Bipin D365 28,964 Super User 2024 Season 1 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

News and Announcements

Announcing Category Subscriptions!

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,359 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,370 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans