locked
CRM 2013 restrict opportunity potential customer to accounts only RRS feed

  • Question

  • We are currently using dynamics 2013.  I need to set the potential customer field on the opportunity form to only list accounts.  I have seen many posts that achieve this through a JavaScript on the OnLoad event of the form.  My issue is that when I use the search function all it filters again by Account and Contacts

    For testing I have limited my JavaScript to:

    function FilteredCustomerLookupAccount() {
    	document.getElementById("customerid").setAttribute("lookuptypes", "1");
    }
    

    All seems fine when the form loads

    All looks fine

    When I start to search, the limitation to Accounts only is lost

    Search lost the filter


    Christo Vermeulen

    Tuesday, September 16, 2014 8:16 AM

Answers

  • You need add a filter to filter out all contacts and fire at PreSearch

    the following code will do it

    let me know if this helps you :-)

    function Form_onload() {
        // Apply preFilter on lookup fields
        document.getElementById("customerid").setAttribute("defaulttype", "1");
        document.getElementById("customerid").setAttribute("lookuptypes", "1");
        document.getElementById("customerid").setAttribute("lookuptypenames", "account:1:Account");
        preFilterLookup();
    }

    function preFilterLookup() {
        Xrm.Page.getControl("customerid").addPreSearch(function () {
            addLookupFilter();
        });
    }

    function addLookupFilter() {

    var contact_filter =”<filter type=’and’>” +
    “<condition attribute=’contactid’ operator=’null’ />” +
    “</filter>”;
     Xrm.Page.getControl("customerid").addCustomFilter(contact_filter, "contact");
    }

     
    Tuesday, October 14, 2014 7:40 PM