Skip to main content

Notifications

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

  • Suggested answer
    Leco Lv Profile Picture
    Leco Lv on at
    RE: script not found

    Hi partner,

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

  • Suggested answer
    Mohamed GRAIB Profile Picture
    Mohamed GRAIB 2,494 Super User 2025 Season 1 on at
    RE: script not found

    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
    Jeroen Janssens Profile Picture
    Jeroen Janssens 15 on at
    RE: script not found

    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);

    }

    }

  • Verified answer
    a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: script not found

    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.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,971 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,846 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans