locked
How to set default entity type (Look For in Lookup Dialog) for Lookup dialog in CRM 2013? RRS feed

  • Question

  • Hi,

    I tried below code to set Look For(Default entity type) for Lookup window in CRM 2013 On-premise.

    document.getElementById("lookUpAttributeName").setAttribute("defaulttype","2");

    But the above code does not work.

    Can anyone help me to set the default entity type for Lookup dialog in CRM 2013.

    Friday, October 25, 2013 10:14 AM

All replies

  • try:-
    Xrm.Page.getControl("customerid").setDefaultView("a2d479c5-53e3-4c69-addd-802327e67a0d");

    Regards Faisal

    Friday, October 25, 2013 3:10 PM
  • I've tried this but this doesn't switch the entity. (in CRM2013)

    For instance. I have a customer field which has 'look for' dropdown filled with 'Account' & 'Contact'.

    If I use the setDefaultView with a View Id from Contact and Account is default selected in the 'look for dropdown' then it will not switch to the correct entity (contact).

    If I do the above with a View Id from Account than it will switch.

    I've checked the attribute list on the 'customerid' field (when getElementById) on CRM2011 and CRM2013. The difference is that in 2011 the attributes 'lookuptypes', 'lookuptypeIcons', 'defaulttype' are all available before you set them. But in CRM2013 this is not the case. Therefor I recon that CRM2013 does not check these values anymore and works in a weird unknown (for me) way.

    Does anyone has a clue how to set the 'defaulttype' and 'lookuptypes' in CRM2013?

    Wednesday, October 30, 2013 7:36 AM
  • Hi.. 

    I am also facing problem with this. i have tried in many ways. but still i am not able to set.

    If anyone got this please let us know.

    Thanks,

    Sravan J

    Wednesday, October 30, 2013 9:08 AM
  • Any progress on resolving this issue?

    H. Sean Shilling, Sr. Solutions Consultant CustomerEffective www.customereffective.com 2009 Microsoft Dynamics CRM Financial Services Partner of the Year

    Thursday, November 21, 2013 9:02 AM
  • Any ideas to resolve this challange?
    Thursday, January 16, 2014 10:37 AM
  • this works for me, hopefully this will help you too...

    var parentcustomerlookup = $("img[attrName='parentcustomerid']");
            if (parentcustomerlookup.length > 0)
            {
                parentcustomerlookup[0].setAttribute("lookuptypenames", "account:1");
                parentcustomerlookup[0].setAttribute("lookuptypes", "1");
                parentcustomerlookup[0].setAttribute("lookuptypeIcons", "/_imgs_ico_16_2.gif?ver=828891367:/_imgs/ico_16_8.gif?ver=828891367");
                parentcustomerlookup[0].setAttribute("createpermissiondictionary", "account:true");
                parentcustomerlookup[0].setAttribute("DefaultViewId", "{A2D479C5-53E3-4C69-ADDD-802327E67A0D}");
                parentcustomerlookup[0].setAttribute("defaulttype", "1");
            }

    Tuesday, September 2, 2014 6:15 PM
  • Disclaimer - Not Supported and copied from web.

    // Function to set Entity to the default option in the Customer Lookup function setDefaultLookupToEntity(ctrl) { try { var c = Xrm.Page.getControl(ctrl); if (c != null) { c.removePreSearch(changeSettings); var changeSettings = function () { c.removePreSearch(changeSettings); var element = document.getElementById(ctrl + "_i"); //unsupported way, needs to be changed if (element) { // Set the default lookup to Contact element.setAttribute("defaulttype", "2"); } }; c.addPreSearch(changeSettings); } } catch (e) { } }

    And Then Call

    setDefaultLookupToEntity("regardingobjectid");
        setDefaultLookupToEntity("optionalattendees");
        setDefaultLookupToEntity("requiredattendees");

    The above code changes the default from Account to Contact on regarding, optional and required fields.

    Regards,

    Jithesh

     
    Wednesday, September 3, 2014 1:15 AM
  • There seems to be an issue with the setDefaultView, and may exist in SP1 as well as 6.0 UR0, UR1 and UR2.

    If you're using SP1 UR1 for SP1 will soon be out and I'll bet this issue gets resolved.

    In the meantime, I believe we're all using this unsupported method.


    I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful. Michael Mayo

    Sunday, September 14, 2014 7:17 PM
  • I know this is an old thread but just in case this helps anyone else...

    In this example, the parentcustomerid attribute was looking at the contact and account entities and I needed to filter out contacts and show only accounts. Simply setting the view didn't work as the moment you search in the lookup field, that view is ignored.

    The solution was to add a preSearch condition for the contact entity where contact id is null. As all contact's will have an id, this effectively excludes the contact entity, leaving only accounts.

    var Sdk = window.Sdk || {};Sdk.filterCustomerAccounts = function () {

    //Filters out contacts from the parentcustomerid field

    var customerAccountFilter = '<filter type="and"><condition attribute="contactid" operator="null" /></filter>';

    Xrm.Page.getControl("parentcustomerid").addCustomFilter(customerAccountFilter, "contact");

    }

    //Add an Onload event handler for the 'Sdk.setParentAccountIdFilter' function

    Sdk.setParentAccountIdFilter = function () {

    Xrm.Page.getControl("parentcustomerid").addPreSearch(Sdk.filterCustomerAccounts);

    }


    Thursday, November 5, 2015 12:52 PM
  • Hi,

    This makes result set to be empty, but the entity type is still possible to select in lookup window. Do you have a solution for that?

    Wednesday, March 2, 2016 11:36 AM