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:
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
Hi partner,
You could write code to check for errors using Visual Studio, Visual Studio Code, or a similar tool.
Hi Die,
Please check the function name and if it's activated or not as shown in the figure below
Hope that's helpful for you
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);
}
}
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.
André Arnaud de Cal...
291,971
Super User 2025 Season 1
Martin Dráb
230,846
Most Valuable Professional
nmaenpaa
101,156