dataverse-web-resources
Dataverse Web Resources
CRITICAL RULES
-
formContextis invalid afterawait. Context objects passed to event handlers are valid only during synchronous execution. After anyawaitor inside.then(),formContext.getAttribute("x").getValue()silently returnsnull— not an error. Extract the VALUES you need (strings, GUIDs, numbers) before the firstawait. Never store the context reference itself across an async boundary. -
preventDefault()is synchronous-only in OnSave. Calling it afterawaitdoes nothing — the save proceeds regardless. If you need to block a save based on async validation, callpreventDefault()synchronously first, then perform the async check and re-enable if valid viasaveEventArguments.enableSaveValidation. -
Never call
formContext.data.entity.save()inside an OnSave handler. This creates a recursive save loop, producing a "Saving in Progress" runtime error visible to the user. -
Xrmis completely unavailable in SiteMap SubArea web resources. NeitherXrmnorparent.Xrmis injected. The only supported approach: include<script src="../../ClientGlobalContext.js.aspx"></script>and callGetGlobalContext()for org context.Xrm.WebApi,Xrm.Navigation, and all otherXrm.*APIs are inaccessible from these pages — there is no workaround. -
Never hardcode
/WebResources/<name>as a URL path. In multi-org environments this silently resolves to the user's default org, not the current one — causing "File Not Found" for users in a non-default org. It also bypasses the platform's browser cache versioning token. Use$webresource:<name>in SiteMap/Ribbon XML, orXrm.Navigation.openWebResource()in code — both embed the version token automatically. -
"Pass execution context as first parameter" MUST be checked. Without it the function receives no argument,
executionContextisundefined, and the firstgetFormContext()call crashes silently. No error is thrown at registration time. -
Async OnSave handlers have a 10-second platform timeout per handler. After timeout the save continues whether or not you called
preventDefault()— the timed-out handler is simply abandoned. Never calldisableAsyncTimeout()unless you can guarantee the async operation cannot hang. -
Always use
$selectinXrm.WebApicalls. Without it every column on every matching record is returned — including multi-line text fields and computed columns. Severe performance impact on grids and high-traffic views.