Monday, 25 February 2019

Show only Account or Contact in customer lookup dynamic 365


To show only account or contact in customer lookup, follow the below steps

1) On Load of form add the following code

if (Xrm.Page.getControl("customerid") != null) {
            Xrm.Page.getControl("customerid").addPreSearch(function () {
                filterCustomerLookup ();
            });
        }

2)Register this function on OnChange event of customer lookup to show only account in customer lookup

    function filterCustomerLookup () {

        var lookup = Xrm.Page.getControl('customerid');

        //check if multiple type dropdowns enabled for this lookup
        if (lookup.getEntityTypes().length > 1) {
            lookup.setEntityTypes(['account']);
        }

        var fetchXml = "<filter type='and'>";
        fetchXml += "<condition attribute='statecode' operator='eq' value='0'/>";
        fetchXml += "</filter>";

        if (Xrm.Page.getAttribute("customerid") != null) {
            Xrm.Page.getControl("customerid").addCustomFilter(fetchXml, "account");
        }
    }



To show only contact  then change account to contact.

function filterCustomerLookup () {

        var lookup = Xrm.Page.getControl('customerid');

        //check if multiple type dropdowns enabled for this lookup
        if (lookup.getEntityTypes().length > 1) {
            lookup.setEntityTypes(['account']);
        }

        var fetchXml = "<filter type='and'>";
        fetchXml += "<condition attribute='statecode' operator='eq' value='0'/>";
        fetchXml += "</filter>";

        if (Xrm.Page.getAttribute("customerid") != null) {
            Xrm.Page.getControl("customerid").addCustomFilter(fetchXml, "contact");
        }
    }


No comments:

Post a Comment

Read only field , get latest value from read only field in in power app portal

Below line is used to make field readonly in power app portal through js $( "#bdo_relationshiprole_name" ).parent().css( "po...