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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to show related contact records from account ?

(0) ShareShare
ReportReport
Posted on by 815

Hi,

This may be old question but it is not working for me.

On the lead page, there are 2 fields "Existing Account" and "Existing Contact" and both has lookup to its respective entity. When Existing account is selected but existing contact is showing all other accounts contact as well. Even changed the filter but still same. I want to stop showing other account contact and show only related account contact.

For testing i created 2 lookup fields to account and contacts and tried same but still no luck.

How to set show related contacts from account ?

Regards

Faisal

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: How to show related contact records from account ?

    Hello,

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

  • Syed_Faisal Profile Picture
    815 on at
    RE: How to show related contact records from account ?

    Hi,

    Tried as suggested but no luck. PFA screenshot.

    Have created 2 accounts WWE & TNA, but the contact filter show all the account's contact

    4061.filter.png

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: How to show related contact records from account ?

    You configured dependency for fields on form but not on BPF. You will have to use coding approach to configure it for header - www.magnetismsolutions.com/.../crm-2013-javascript-lookup-filtering-using-addcustomfilter

  • gdas Profile Picture
    50,091 Moderator on at
    RE: How to show related contact records from account ?

    Hi Faisal,

    Try with this , register ContactLookupFieldFilter function  in the onload of the lead form as well as onchange of account and contact lookup.

    function ContactLookupFieldFilter() {
        // add the event handler for PreSearch Event
        Xrm.Page.getControl("ContactLookUpFieldName").addPreSearch(addFilter); // For form field
        if (Xrm.Page.getControl("header_process_ContactLookUpFieldName") != null && Xrm.Page.getControl("header_process_ContactLookUpFieldName") != undefined) {
            Xrm.Page.getControl("header_process_ContactLookUpFieldName").addPreSearch(addFilter);  // For BPF field
        }
    }
    
    function addFilter() {
        var AccountLookup = Xrm.Page.getControl("AccountLookupID").getAttribute().getValue(); // Put the Account Lookup ID ,make sure if your lookup does not exists in the form then add header_process with the field name 
        if (AccountLookup != null && AccountLookup != undefined) {
            var AccountId = AccountLookup[0].id;
            //create a filter xml
            var filter = "<filter type='and'>" +
            "<condition attribute='parentcustomerid'  value='" + AccountId + "'/>" +
            "</filter>";
            //add filter
            Xrm.Page.getControl("ContactLookUpFieldName").addCustomFilter(filter); // For Form field
    
            if (Xrm.Page.getControl("header_process_ContactLookUpFieldName") != null && Xrm.Page.getControl("header_process_ContactLookUpFieldName") != undefined) {
                Xrm.Page.getControl("header_process_ContactLookUpFieldName").addCustomFilter(filter); //For BPF field
            }
        }
    }
    

  • Verified answer
    Nithya Gopinath Profile Picture
    17,078 on at
    RE: How to show related contact records from account ?

    Hi Syed Faisal,

    Try using the code below.

    function filterLookup() {
        //Check if the control exist on the form
        if (Xrm.Page.getControl("header_process_parentcontactid") != null) {
            // add the event handler for PreSearch Event
            Xrm.Page.getControl("header_process_parentcontactid").addPreSearch(addFilter);
        }
    }
    function addFilter() {
        var accountId = null;
        var accountLookup;
        var fetchQuery;
        try {
            //Check if control exist on form
            if (Xrm.Page.getControl("header_process_parentaccountid") != null && Xrm.Page.getControl("header_process_parentaccountid").getAttribute().getValue() != null) {
    
                //Get Account lookup value
    
                accountLookup = Xrm.Page.getControl("header_process_parentaccountid").getAttribute().getValue();
                //Get the account id
                accountId = accountLookup[0].id;
            }
            //Build fetch
            if (accountId != null || accountId != undefined) {
                fetchQuery = "<filter type='and'>" +
    "<condition attribute='statecode' operator='eq' value='0' />" +
    "<condition attribute='parentcustomerid' operator='eq' value='" + accountId + "' />" +
    "</filter>";
                //add custom filter
                Xrm.Page.getControl("header_process_parentcontactid").addCustomFilter(fetchQuery);
            }
        } catch (e) {
            Xrm.Utility.alertDialog("addFilter Error: " + (e.description || e.message));
        }
    }

    Refer the link below.

    www.inogic.com/.../how-to-apply-script-on-header-fields-and-bpf-fields

    Hope this helps.

  • Syed_Faisal Profile Picture
    815 on at
    RE: How to show related contact records from account ?

    Hi Gowtham,

    It's not working for me. On the lead page i have created 2 custom fieldname as "Existing Customer" and "Existing Contact".

    Then created JS and added on the form on load as well on change in the field.

    When i search still it is showing all the contacts.

  • Syed_Faisal Profile Picture
    815 on at
    RE: How to show related contact records from account ?

    Hi,

    Finally i have fixed contacts lookup. Pl see the screenshot.

    Contacts-Filter.png

    But same look field is not working on BPF header, can you please help.

    Regards

    Faisal

  • Syed_Faisal Profile Picture
    815 on at
    RE: How to show related contact records from account ?

    Hello All

    Issue is fixed. Thanks a lot Nithya for the solution.

    Regards

    Faisal

  • Syed_Faisal Profile Picture
    815 on at
    RE: How to show related contact records from account ?

    Hi Nithya,

    The code which you have send is working fine and i need to add 1 more account lookup field. I tried same code and modified the field name but at a time only 1 lookup work.

    Can you please help ?

  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at
    RE: How to show related contact records from account ?

    Hi Syed,

    Where did you add the new lookup field? What is the logical name of the lookup field? Do you need to show related contacts from both these account lookup fields in contact field?

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

#3
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans