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!
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!
I reviewed the code. And it's written the way you wanted it to work.
OK will look, thanks. Can you review the code again? Does it not need a setVisible true, else, false...so that the field is shown for all roles except for *BF Field Service - Resource?
Usage of the Guid is possible but I won't recommend going this path.
You can run the following code from the Developer tools to verify that your user really has that role:
var userRoles = Xrm.Utility.getGlobalContext().userSettings.roles.getAll();
var allRoles = userRoles.map(role => role.name).join("\r\n");
alert(allRoles);
And one more recommendation - learn a bit of troubleshooting your code. That won't harm - www.youtube.com/watch
Maybe need to use GUID instead of name?
Can you please provide the exact name of the role?
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?
Ok. Checked in my instance. The right name for that control is header_msdyn_systemstatus. Check that out.
Thanks again. Implemented that and am still getting the script error Cannot read properties of null (reading 'setVisible')
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); }
It is in the header. It does have Field Level Security against it OOB.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,620 Super User 2024 Season 2
Martin Dráb 228,884 Most Valuable Professional
nmaenpaa 101,150