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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

script not found

(0) ShareShare
ReportReport
Posted on by 15

I am trying to make a custom view for a custom form on a custom entity based on this article: https://www.inogic.com/blog/2014/09/add-custom-view-in-lookup-and-disable-all-the-other-views/

This is my code:

function setCustomView() {

var functionName = “setCustomView”;

try {

//Check whether the field exist or not

if (isValid(Xrm.Page.getControl(“sgw_behandelaar”))) {

// add the randomly generated GUID for the view id
//var viewId = ‘{00000000-0000-0000-0000-000000000001}’;
var viewId = Xrm.Page.getControl(“sgw_behandelaar”).getDefaultView();

var team= Xrm.Page.getAttribute(“sgw_verantwoordelijkedienst”).getValue();

//add the entity name

var entityName = “systemuser”;

// add the view display name

var viewDisplayName = “Gebruikers van de dienst”;

// fetch xml for filtered records

var fetchXml = “<fetch version=‘1.0’ output-format=‘xml-platform’ mapping=‘logical’ distinct=‘true’> “ +
“<entity name=‘systemuser’> “ +
“<attribute name=‘fullname’ /> “ +
“<attribute name=‘systemuserid’ /> “ +
“<order attribute=‘fullname’ descending=‘false’ /> “ +
“<filter type=‘and’> “ +
“<condition attribute=‘isdisabled’ operator=‘eq’ value=‘0’ /> “ +
“</filter> “ +
“<link-entity name=‘teammembership’ from=‘systemuserid’ to=‘systemuserid’ visible=‘false’ intersect=‘true’> “ +
“<link-entity name=‘team’ from=‘teamid’ to=‘teamid’ alias=‘ac’> “ +
“<filter type=‘and’> “ +
“<condition attribute=‘name’ operator=‘eq’ value=‘” + team + “‘/>“ +
“</filter> “ +
“</link-entity> “ +
“</link-entity> “ +
“</entity> “ +
“</fetch> “ ;

//Grid Layout for filtered records

var layoutXml = “<grid name=‘resultset’ object=‘1′ jump=‘productid’ select=‘1′ icon=‘1′ preview=‘1′>“ +

“<row name=‘result’ id=‘systemuser’>“ +

“<cell name=‘fullname’ width=‘150′ />“ +

“</row>“ +

“</grid>“;

// add the custom view for the lookup field

Xrm.Page.getControl(“sgw_behandelaar”).addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, true);

}

} catch (e) {

throwError(e, functionName);

}

}

The form properties are set:

forum20230103_5F00_1.png_2D00_640x480.png

But when I load the page I get the following error:

ReferenceError: Web resource method does not exist: setCustomView
at y._handleMethodNotExistError (xxxxxxxxxxxx.crm4.dynamics.com/.../app.js
at y.execute (https://xxxxxxxxxxxx.crm4.dynamics.com/uclient/scripts/app.js?v=1.4.5024-2211.2:2078:3715)
at https://xxxxxxxxxxxx.crm4.dynamics.com/uclient/scripts/app.js?v=1.4.5024-2211.2:164:26979
at i (https://xxxxxxxxxxxx.crm4.dynamics.com/uclient/scripts/app.js?v=1.4.5024-2211.2:351:88)
at ee._executeIndividualEvent (https://xxxxxxxxxxxx.crm4.dynamics.com/uclient/scripts/app.js?v=1.4.5024-2211.2:164:26953)
at ee._executeEventHandler (https://xxxxxxxxxxxx.crm4.dynamics.com/uclient/scripts/app.js?v=1.4.5024-2211.2:164:23958)
at Object.execute (https://xxxxxxxxxxxx.crm4.dynamics.com/uclient/scripts/app.js?v=1.4.5024-2211.2:164:21175)
at N._executeSyncAction (https://xxxxxxxxxxxx.crm4.dynamics.com/uclient/scripts/app.js?v=1.4.5024-2211.2:970:692)
at N._executeSync (https://xxxxxxxxxxxx.crm4.dynamics.com/uclient/scripts/app.js?v=1.4.5024-2211.2:970:419)
at N.executeAction (https://xxxxxxxxxxxx.crm4.dynamics.com/uclient/scripts/app.js?v=1.4.5024-2211.2:970:201)

Foutdetails:
Naam van gebeurtenis: onload
Function Name: setCustomView
Naam van webresource: sgw_taakvergadering.js
Oplossingsnaam: Active
Naam van uitgever: DefaultPublisherxxxxxxxxxxxx

I have the same question (0)
  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    I believe the issue is related to the quotes used in the code.

    Try to replace “ and ” with " and ‘ and ’ with '.

    Also, you can use beautifytools.com/javascript-validator.php to validate your JavaScript.

  • Suggested answer
    Jeroen Janssens Profile Picture
    15 on at

    Thanks for the help.  That got me started.  I also needed to change xrm.page commands to formcontext commands.

    My final code was the following and does exactly what I wanted it to do!

    function setCustomView(executionContext) {

    var formcontext = executionContext.getFormContext();

    if (formcontext.getAttribute("sgw_verantwoordelijkedienst").getValue() != null) {

    var viewId = formcontext.getControl("sgw_behandelaar").getDefaultView();

    var team = formcontext.data.entity.attributes.get("sgw_verantwoordelijkedienst");

    var teamid = team.getValue()[0].id.slice(1,-1);

    var entityName = "systemuser";

    var viewDisplayName = "Gebruikers van de dienst";

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

    "<entity name='systemuser'> " +

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

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

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

    "<filter type='and'> " +

    "<condition attribute='isdisabled' operator='eq' value='0' /> " +

    "</filter> " +

    "<link-entity name='teammembership' from='systemuserid' to='systemuserid' visible='false' intersect='true'> " +

    "<link-entity name='team' from='teamid' to='teamid' alias='ac'> " +

    "<filter type='and'> " +

    "<condition attribute='teamid' operator='eq' value='" + teamid + "'/>" +

    "</filter> " +

    "</link-entity> " +

    "</link-entity> " +

    "</entity> " +

    "</fetch> ";

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

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

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

    "</row>" +

    "</grid>";

    formcontext.getControl("sgw_behandelaar").addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, true);

    }

    }

  • Suggested answer
    Mohamed GRAIB Profile Picture
    2,504 Moderator on at

    Hi Die, 

    Please check the function name and if it's activated or not as shown in the figure below 

    pastedimage1672820370035v1.png

    Hope that's helpful for you

  • Suggested answer
    Leco Lv Profile Picture
    on at

    Hi partner,

    You could write code to check for errors using Visual Studio, Visual Studio Code, or a similar tool.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Martin Dráb Profile Picture

Martin Dráb 49 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 38 Super User 2025 Season 2

#3
#ManoVerse Profile Picture

#ManoVerse 31

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans