locked
filter lookup hide view RRS feed

  • Question

  • Hi

    Im using the  Xrm.Page.getControl("customerid").setDefaultView - function to prefilter a specifik lookup based on a picklist value. 

    but i also want that this view should be the one and only available view to select and search records from. 

    is there any way to lock the lookup form to a specifik view, or hide all the other views? (by using javascript) 

    /F

    Thursday, August 14, 2014 3:42 PM

All replies

  • This is actually possible with some use of undocumented lookup features.

    If you set the "disableViewPicker" html attribute to 1 before you open the lookup it will open disabled.

    There’s a catch to this though,  cause In order the add custom views the View Picker must be enabled, otherwise it won’t work.  so remember to enable the view before adding a view and disable it afterwards if necessary.

    Here is a fancy implementation of an XrmLookupField wrapper that does all the job for you.

    Of course you can just use the lines that actually disable and enable the View Picker.

    //SDK wrapper for lookup field
    function XrmLookupField(sId) {
        var xlf = this;
        //control instance
        xlf.Ctl = Xrm.Page.getContorl(sId);
        //dom instance
        xlf.Dom = document.getElementById(sId);
        //jquery instance
        xlf.$ = $(xlf.Dom);
    
        //2013 addition
        xlf.$i = $("#" + sId + "_i");
        //use that to disable the view picker
        xlf.DisableViewPicker = function () { 
            xlf.SetParameter("disableviewpicker", "1"); 
        }
        //use that to enable the view picker
        xlf.EnableViewPicker = function () { 
            xlf.SetParameter("disableviewpicker", "0");  
        }
        //set undocumented attributes
        xlf.SetParameter = function (sName, vValue) { 
            xlf.$.attr(sName, vValue);  
    
            //2013 addition
            xlf.$i.attr(sName, vValue);
        }   
        //add locked view
        xlf.AddLockedView = function (sViewId, sEntityName, sViewDisplayName, sFilterXml, sFilterLayout, oSettings) {
    
            //first enable the view picker
            xlf.EnableViewPicker();
            //add the custom view (last parameter set the view as default)
            xlf.Ctl.addCustomView(sViewId, sEntityName, sViewDisplayName, sFilterXml, sFilterLayout, true);
    
            //lock the view picker
            xlf.DisableViewPicker();
        }
    }
    
    //entity onload js
    var myLookup1;
    
    
    function OnCrmPageLoad() {
        myLookup1 = new XrmLookupField("new_lookup1");
        myLookup1.AddLockedView(/*  add custome view params */);
    }
       
    

    Sorry, wrote it from memory.  With 2013 the layout changed and so there are also small behavioral differences between the versions.

    First the disableviewpicker attribute name is not longer capitalized and second, the attribute also exist on the inline edit control and need to be set accordingly.

    The code reflect those changes now.

    Cheers




    Dev Blog: Dynamics CRM - Thinking outside the Box




    • Edited by Adi Katz Friday, August 15, 2014 2:13 PM
    Thursday, August 14, 2014 6:29 PM
  • This is actually possible with some use of undocumented lookup features.

    If you set the "disableViewPicker" html attribute to 1 before you open the lookup it will open disabled.

    There’s a catch to this though,  cause In order the add custom views the View Picker must be enabled, otherwise it won’t work.  so remember to enable the view before adding a view and disable it afterwards if necessary.

    Here is a fancy implementation of an XrmLookupField wrapper that does all the job for you.

    Of course you can just use the lines that actually disable and enable the View Picker.

    //SDK wrapper for lookup field function XrmLookupField(sId) { var xlf = this; //control instance xlf.Ctl = Xrm.Page.getContorl(sId);
    //dom instance xlf.Dom = document.getElementById(sId);
    //jquery instance xlf.$ = $(xlf.Dom); //use that to disable the view picker xlf.DisableViewPicker = function () { xlf.SetParameter("disableViewPicker", "1"); } //use that to enable the view picker xlf.EnableViewPicker = function () { xlf.SetParameter("disableViewPicker", "0"); } //set undocumented attributes xlf.SetParameter = function (sName, vValue) { xlf.$.attr(sName, vValue); } //add locked view xlf.AddLockedView = function (sViewId, sEntityName, sViewDisplayName, sFilterXml, sFilterLayout, oSettings) {

    //first enable the view picker
    xlf.EnableViewPicker();
    //add the custom view (last parameter set the view as default) xlf.Ctl.addCustomView(sViewId, sEntityName, sViewDisplayName, sFilterXml, sFilterLayout, true);

    //lock the view picker xlf.DisableViewPicker(); } } //entity onload js var myLookup1;

    function OnCrmPageLoad() { myLookup1 = new XrmLookupField("new_lookup1"); myLookup1.AddLockedView(/* add custome view params */); }



    Dev Blog: Dynamics CRM - Thinking outside the Box

    Are u sure that will work with CRM2013?

    Friday, August 15, 2014 9:36 AM
  • code updated ...

    Dev Blog: Dynamics CRM - Thinking outside the Box

    Friday, August 15, 2014 4:52 PM
  • I’ve created a post blog about this. Maybe seeing it in "action" will make more sense.

    http://totbcrm.blogspot.com/2014/08/disabling-lookup-view-picker-in-crm-2013.html

    Cheers,

    Adi


    Dev Blog: Dynamics CRM - Thinking outside the Box

    Friday, August 15, 2014 7:44 PM