Notifications
Announcements
No record found.
Hi, Looking for a quick sample code to hide a field (msdyn_systemstatus) on the Work Order entity when user Security Role = "*BF Field Service - Resource". Does anyone have a few lines for this that I can review and test?Thanks!
Hello,
Check this code:
function workorderOnLoad(executionContext) { var formContext = executionContext.getFormContext(); var userRoles = Xrm.Utility.getGlobalContext().userSettings.roles.getAll(); var roleAvailable = userRoles.some(function(role) { return role.name === "*BF Field Service - Resource"; }); formContext.getControl("msdyn_systemstatus").setVisible(!roleAvailable); }
Thanks! Looks like when I implement that onLoad there is an error on setVisible...
TypeError: Cannot read properties of null (reading 'setVisible')
at HideWOSystemStatus (bridgestonevandev.crm.dynamics.com/.../bf_HideWOSystemStatus:9:46)
at y._executeFunctionInternal (bridgestonevandev.crm.dynamics.com/.../app.js
at y.execute (bridgestonevandev.crm.dynamics.com/.../app.js
at bridgestonevandev.crm.dynamics.com/.../app.js
at i (bridgestonevandev.crm.dynamics.com/.../app.js
at ee._executeIndividualEvent (bridgestonevandev.crm.dynamics.com/.../app.js
at ee._executeEventHandler (bridgestonevandev.crm.dynamics.com/.../app.js
at Object.execute (bridgestonevandev.crm.dynamics.com/.../app.js
at N._executeSyncAction (bridgestonevandev.crm.dynamics.com/.../app.js
at N._executeSync (bridgestonevandev.crm.dynamics.com/.../app.js
Error Details:
Event Name: onload
Function Name: HideWOSystemStatus
Web Resource Name: msdyn_/WorkOrder/WorkOrder.Library.js
Solution Name: msdyn_FieldService_patch_update
Publisher Name: microsoftdynamics
Are you sure that the field is present on the form? Can you please provide the screenshot of the form?
It is in the header. It does have Field Level Security against it OOB.
Gotcha. Header controls are different. Try to use the following code:
function workorderOnLoad(executionContext) { var formContext = executionContext.getFormContext(); var userRoles = Xrm.Utility.getGlobalContext().userSettings.roles.getAll(); var roleAvailable = userRoles.some(function(role) { return role.name === "*BF Field Service - Resource"; }); formContext.getControl("header_process_msdyn_systemstatus").setVisible(!roleAvailable); }
Thanks again. Implemented that and am still getting the script error Cannot read properties of null (reading 'setVisible')
Ok. Checked in my instance. The right name for that control is header_msdyn_systemstatus. Check that out.
OK, error has ceased to appear. However, the I have the Security Role and the field still is shown on the form (header). Any ideas?
Can you please provide the exact name of the role?
Maybe need to use GUID instead of name?
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.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Tom_Gioielli 83 Super User 2025 Season 2
Gerardo RenterÃa Ga... 49 Most Valuable Professional
#ManoVerse 40