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 and setDefaultView not working correctly

(0) ShareShare
ReportReport
Posted on by

Hi all,

i'm using Javascript to add a custom view to a custom Lookup. but it did not work correctly

this is my code

control = Xrm.Page.getControl("febb_textmoduleid");

   if (control != null) {

       var entityTypeName = Xrm.Page.data.entity.getEntityName();

       var filter = "<filter type='and'>"

                         + "<filter type='or'>"

                           + "<condition attribute='febb_entityname' operator='like' value='%%%' />"

                           + "<condition attribute='febb_entityname' operator='like' value='%" + entityTypeName + "%' />"

                         + "</filter>"

                       + "</filter>";

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

                     + "<entity name='febb_textmodule'>"

                       + "<attribute name='febb_textmoduleid' />"

                       + "<attribute name='febb_name' />"

                       + "<attribute name='febb_text' />"

                       + "<order attribute='febb_name' descending='false' />"

                       + filter

                     + "</entity>"

                   + "</fetch>";

       var layoutXml = "<grid name='resultset' object='10020' jump='febb_name' select='1' icon='1' preview='1'>"

                         + "<row name='result' id='febb_textmoduleid'>"

                           + "<cell name='febb_name' width='150' />"

                           + "<cell name='febb_text' width='300' disableSorting='1' />"

                         + "</row>"

                       + "</grid>";

       //control.addCustomFilter(filter);

       var viewName = "Available Text Modules for this Entity";

       var viewId = "{" + febb.Helpers.GenerateGuid() + "}";

       //debugger;

       control.addCustomView(viewId, "febb_textmodule", viewName, fetchXml, layoutXml, false);

       control.setDefaultView(viewId);

   }

if i click the lookup i receive the error Message "Record Is Unabailable - Record not found or no permissions to view it".

But if i click on "Lookup more Records" after the error message. The custom view is set as default and the view is working correctly.

what is wrong?

View selector is enabled.

Ciao

Pascal

*This post is locked for comments

I have the same question (0)
  • ScottDurow Profile Picture
    21 on at

    Hi,

    You've probably done this already - but check that the target entity on the lookup is the same as the type you are setting (febb_textmodule). I've had these kind of errors if the entity logical names are different.

    Hope this helps,

    Scott

  • Verified answer
    Community Member Profile Picture
    on at

    Hi Scott,

    i checked this and i added a variable with the entityname to make sure, it is the same in all cases... same result.

    in the meanwhile i saw that CRM Guids are UpperCase... so i changed the lines 

    control.addCustomView(viewId, "febb_textmodule", viewName, fetchXml, layoutXml, false);

    control.setDefaultView(viewId);


    to

    control.addCustomView(viewId.toUpperCase(), textModuleEntityName, viewName, fetchXml, layoutXml, false);

    control.setDefaultView(viewId.toUpperCase());

    Now it is working...

    Thanks for help



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