web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

addCustomView method for lookup field shrinks the lookup filed width

(0) ShareShare
ReportReport
Posted on by

Hi,

I am trying to add the custom view to the lookup field and setting that custom view as the default view as below:

 Xrm.Page.getControl(fieldName).addCustomView(viewId, 'product', viewDisplayName, fetchXml, layoutXml, true);

Please find the image below:

The line item field lookup shrinks.5700.Capture.PNG

*This post is locked for comments

I have the same question (0)
  • Rajkumar Rajaraman Profile Picture
    on at

    Surya,

    Have you tried different browsers?

    Also refer this:

    inogic.com/.../add-custom-view-in-lookup-and-disable-all-the-other-views

    Hope this helps.

    Regards,

    R.Rajkumar

    "Please mark my answer as verified if you found it helpful"

  • Community Member Profile Picture
    on at

    Hi RajKumar,

    I tried in chrome and IE11. I gone through the link. but the issue is that lookupfield textbox area gets shrinks after the record is selected.

  • Rajkumar Rajaraman Profile Picture
    on at

    Surya,

    Try this, setting the IsDefaultView to false in addCustomView() method

    Refer the following link:

    stackoverflow.com/.../ms-crm-lookup-field-ui-is-messed-up-with-custom-filter

    Hope this helps.

    Regards,

    R.Rajkumar

    "Please mark my answer as verified if you found it helpful"

  • Community Member Profile Picture
    on at

    Ya i tried. But it displays all the records. I want to display records from the customized view.

  • Rajkumar Rajaraman Profile Picture
    on at

    Have you updated latest rollup?

  • Community Member Profile Picture
    on at

    Currently using update 0.1

  • Rajkumar Rajaraman Profile Picture
    on at

    Post your code on here

  • Community Member Profile Picture
    on at
      var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true' >"
                    fetchXml += "<entity name='product' >"
                    fetchXml += "<attribute name='new_productid' />"
                    fetchXml += "<attribute name='productnumber' />"
                    fetchXml += "<attribute name='name' />"
                    fetchXml += "<order attribute='name' descending='false' />"
                    fetchXml += "<filter type='and'>";
                    fetchXml += "<condition attribute='new_productid' operator='eq' value = '";
                    fetchXml += productId;
                    fetchXml += "' />";
                    fetchXml += "<condition attribute='new_class' operator='eq' value ='Sample'/>";
                    fetchXml += "</filter>";
                    fetchXml += "</entity>" + "</fetch>";              
    
                    var viewId = "{00000000-0000-0000-00AA-000010001111}";
                    var viewDisplayName = "Sample SKUs";
    
    
                    var layoutXml = "<grid name='resultset' object='1' jump='name' select='1' icon='1'  preview='1'>" +
                  "<row name='result' id='productid'>" +
                  "<cell name='name'  width='300' />"+
                  "<cell name='productnumber'  width='300'/>" +
                  "</row>" +
                  "</grid>";
    
                    Xrm.Page.getControl("new_LineItem").addCustomView(viewId, 'product', viewDisplayName, fetchXml, layoutXml, true);
  • Rajkumar Rajaraman Profile Picture
    on at

    Use this,

    var viewId = Xrm.Page.getControl("new_productid").getDefaultView();

    instead of

    var viewId = "{00000000-0000-0000-00AA-000010001111}";

    Also change to var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"

  • Verified answer
    Community Member Profile Picture
    on at
    1. var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true' >"
    2. fetchXml += "<entity name='product' >"
    3. fetchXml += "<attribute name='productid' />"
    4. fetchXml += "<attribute name='new_productid' />"
    5. fetchXml += "<attribute name='productnumber' />"
    6. fetchXml += "<attribute name='name' />"
    7. fetchXml += "<order attribute='name' descending='false' />"
    8. fetchXml += "<filter type='and'>";
    9. fetchXml += "<condition attribute='new_productid' operator='eq' value = '";
    10. fetchXml += productId;
    11. fetchXml += "' />";
    12. fetchXml += "<condition attribute='new_class' operator='eq' value ='Sample'/>";
    13. fetchXml += "</filter>";
    14. fetchXml += "</entity>" + "</fetch>";
    15.  
    16. var viewId = "{00000000-0000-0000-00AA-000010001111}";
    17. var viewDisplayName = "Sample SKUs";
    18.  
    19.  
    20. var layoutXml = "<grid name='resultset' object='1' jump='name' select='1' icon='1' preview='1'>" +
    21. "<row name='result' id='productid'>" +
    22. "<cell name='name' width='300' />"+
    23. "<cell name='productnumber' width='300'/>" +
    24. "</row>" +
    25. "</grid>";
    26.  
    27. Xrm.Page.getControl("new_LineItem").addCustomView(viewId, 'product', viewDisplayName, fetchXml, layoutXml, true);

    Please Include productid column in fetch XML and try.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans