Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- RemoveLeadSourcesForSpecificSecurityRoles = function (executionContext) {
- //get the Source field on the form
- var sourceField = executionContext.getFormContext().getControl("header_source");
- //Lead Sources will be removed for this list of Security Roles
- var secruityRoles = [
- "Manager",
- "TeamLead",
- "RegionalManager"
- ];
- //The list of option set items to be removed from Source field for the above Security Roles
- var leadSources = [
- 174920000, //Source1
- 174920003, //Source2
- 174920006, //Source3
- 174920010, //Source4
- 174920009 //Source5
- ];
- //get logged in User's Security Roles
- var currentUserRoles = Xrm.Utility.getGlobalContext().userSettings.securityRoles;
- //create this matchprevfound variable so that we don't remove option set values multiple times. Only remove option set values once if a security role matches
- var matchPrevFound = false;
- //get the names of each of the User's Security Roles
- for (i=0; i < currentUserRoles.length; i++) {
- Xrm.WebApi.retrieveRecord("role", currentUserRoles[i], "$select=name").then(
- function success(result) {
- if (secruityRoles.includes(result.name) && matchPrevFound== false) {
- matchPrevFound = true;
- for (i=0; i < leadSources.length; i++) {
- sourceField.removeOption(leadSources[i]);
- }
- }
- });
- }
- }
Add Comment
Please, Sign In to add comment