Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Answered

Form Javascript example needed - Hide 2 Option Set values when Security role does not eq Sys Admin

Posted on by

Hello, 
I am looking for a code example to compare.  I have a requirement where if a WO System Status (msdyn_systemstatus, which is located in the Header of the form) = 690,970,002 or 690,970,003, that for every role EXCEPT System Administrator, those must be hidden.  Thanks in advance for any feedback or examples! 


  • Verified answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Form Javascript example needed - Hide 2 Option Set values when Security role does not eq Sys Admin

    Hello,

    Try the following code:

    function workorderOnLoad(executionContext) {
    	var formContext = executionContext.getFormContext();
    	var userRoles = Xrm.Utility.getGlobalContext().userSettings.roles.getAll();
    	var systemAdministratorRoleAvailable = userRoles.some(function(role) {
    		return role.name === "System Administrator";
    	});
    
    	if (systemAdministratorRoleAvailable) {
    		return;
    	}
    
    	formContext.getControl("header_process_msdyn_systemstatus").removeOption(690970002);
    	formContext.getControl("header_process_msdyn_systemstatus").removeOption(690970003);
    }

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans