Search This Blog

Sunday, November 22, 2015

Display/Show CRM default Lookup(Lookup more records) window using Javascript

Display/Show CRM default Lookup(Lookup more records) window using Javascript

If you have any doubt in the post please post comments. I will try to solve your problem.

With the help of java-script we can display CRM lookup more records form for any entity .


URL:/_controls/lookup/lookupinfo.aspx?paremeter
Parameter:
&DefaultType=ObjectTypeCode
&DefaultViewIdViewId
&DisableQuickFind=0(Do you want quick find enable or not disable) Enable=1 Disable=0
&DisableViewPicker=0(Do you want quick view picker enable or not disable)
&IsInlineMultiLookup=0
&LookupStyle=Lookup Style(single)
&ShowNewButton=1 (Do you want new button enable or not disable)
&ShowPropButton=1 (Do you want prop button enable or not disable)
&dType=1
&mrsh=false
&objecttypes=ObjectTypeCode
&search=Searchstring 

Example:
    var strSearch = Xrm.Page.getAttribute('shipto_postalcode').getValue();
        var strURL = "_controls/lookup/lookupinfo.aspx?AllowFilterOff=0&DefaultType=10161&DefaultViewId=%7b141FCA27-5F72-E511-9418-0050568107AE%7d&DisableQuickFind=0&DisableViewPicker=0&IsInlineMultiLookup=0&LookupStyle=single&ShowNewButton=0&ShowPropButton=1&dType=1&mrsh=false&objecttypes=10161&search=";
        strURL += strSearch;
        var oUrl = Mscrm.CrmUri.create(strURL);

        var dialogwindow = new Mscrm.CrmDialog(oUrl, window, 500, 600);

        //use setCallbackReference method to call some handler once dialog is closed
        //to result variable would be returned result of dialog call
        dialogwindow.setCallbackReference(function(result) {
       
        });

        //call this method to show dialog

        dialogwindow.show();

Filter types in CRM lookup window:

  • Filter a single column in the lookup window
  • Filter  multiple column in the lookup window

1) Filter a single columns( where country='usa') in the lookup window grid.

Solution:
It  is possible in both     CRM On-Premises and On-line.The value can be set both dynamically and static value.
    Static:
       Customization->Entity->views->Add filter in that form. Call that form in javascript.
    Dynamic:
        Pass the filter value in the "lookupinfo,aspx" query string with key name search.

2) Filter multi-column( where country='usa' and state='ny')  in the lookup window grid

Solutions:
The value can be set both dynamically and static in CRM On-Premises but in CRM online the only static value can be possible,because we can't able to access server page in CRM online.
  Static:
       Customization->Entity->views->Add filter in that form. Call that form in javascript.
  Dynamic:
      To copy the lookupSingle.aspx (C:\Program Files\Microsoft Dynamics CRM\CRMWeb\_controls\lookup\lookupSingle.aspx) form in server  and create a new aspx form in server. When you call this form in javascript pass your own parameter in the query string. In the aspx form you get that value and add filter in the fetch xml and load the grid.


17 comments:

  1. Hi, i have one doubt here, if i have a custom view to show here, how i get here?

    ReplyDelete
  2. IN DefaultViewId parameter give your custom view id

    ReplyDelete
  3. Hi , how can I call this custom lookup from the click of lookup field , when I click on lookup field I want to show this custom lookup directly.

    ReplyDelete
  4. Hi , how can I call this custom lookup from the click of lookup field , when I click on lookup field I want to show this custom lookup directly.

    ReplyDelete
    Replies
    1. Hi Vilas,
      Let's take an example of account page, we have a parent account lookup the id value of the field is "parentaccountid_i"(To get the id: Press F12 in chrome go to elements tabs click mouse pointer in the parent account field, from there you get the corresponding parent account lookup button id name).

      $('#parentaccountid_i').attr('eventName','value')
      eventName=Parameter given in the blog
      value= value to which you want to set

      Delete
  5. thanks for this, it works great when using the browser for our crm 2016 solution.

    However i can't get it to work when using the outlook client (outlook 2010 + crm for outlook 2016). The dialog opens as expected but the callback is never executed when it closes again.

    The outlook client seems to be exclusively synchronous in its execution.

    I've tried modal dialog as a alternative just for outlook (its pure MS here so that should be future proof) but then i get a error when i try to do anything with the returned object (can't execute code from freed script)
    the freed script refers to the script of the dialog that created the object but that is now unloaded as the dialog has closed.

    ReplyDelete
    Replies
    1. Hey did you find the solution for your problem.If yes please let me know because i have the same scenario, Where i can open the dailog but could not set the callback function

      Delete
    2. We went with the modal dialog approach, which seems to work now. Also we made sure to open the window from a CRM webresources so there is no cross-domain problems. The code for the outlook client now looks like this:
      if (isOutlook()) {
      selecteditem = window.showModalDialog(url, null, 'dialogHeight:600px;dialogWidth:600px');

      if (!selecteditem) {
      return null;
      }
      callback(selecteditem.items.length > 0
      ? new LookupControlItem(selecteditem.items[0].id, selecteditem.items[0].type, selecteditem.items[0].name)
      : false);
      }

      'Callback' here is the function that is passed into the function that opens the dialog. you pass in a function to execute when the dialog is closed.

      Delete
  6. how to provide filter by related entity parameter

    ReplyDelete
  7. Hello @Alagunellaikumar,
    Can you provide example of how to form a search query with multiple parameters?

    ReplyDelete
    Replies
    1. I want to Search on a column in view, which is not an entity's primary field

      Delete
  8. when I click on lookup field I want to show this custom lookup directly.IMO for Windows

    ReplyDelete
  9. I want to show this custom lookup directly. How can I do that?
    Kik for PC

    ReplyDelete
  10. Hey Is their any alternative for Mscrm.CrmDialog?

    ReplyDelete
  11. • I very much enjoyed this article. Nice article thanks for given this information. I hope it useful to many Peopledata since Online Training hyderabad

    ReplyDelete
  12. • Nice and good article. It is very useful for me to learn and understand easily. Thanks for sharing your valuable information and time. Please keep updatingAzure Online Training

    ReplyDelete
  13. This is my first time i visit here and I found so many interesting stuff in your blog especially it's discussion, thank you. Joox Music PC

    ReplyDelete

Note: Only a member of this blog may post a comment.