Guest User

Untitled

a guest
Nov 17th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. RemoveLeadSourcesForSpecificSecurityRoles = function (executionContext) {
  2. //get the Source field on the form
  3. var sourceField = executionContext.getFormContext().getControl("header_source");
  4.  
  5. //Lead Sources will be removed for this list of Security Roles
  6. var secruityRoles = [
  7. "Manager",
  8. "TeamLead",
  9. "RegionalManager"
  10. ];
  11.  
  12. //The list of option set items to be removed from Source field for the above Security Roles
  13. var leadSources = [
  14. 174920000, //Source1
  15. 174920003, //Source2
  16. 174920006, //Source3
  17. 174920010, //Source4
  18. 174920009 //Source5
  19. ];
  20.  
  21. //get logged in User's Security Roles
  22. var currentUserRoles = Xrm.Utility.getGlobalContext().userSettings.securityRoles;
  23.  
  24. //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
  25. var matchPrevFound = false;
  26.  
  27. //get the names of each of the User's Security Roles
  28. for (i=0; i < currentUserRoles.length; i++) {
  29. Xrm.WebApi.retrieveRecord("role", currentUserRoles[i], "$select=name").then(
  30. function success(result) {
  31. if (secruityRoles.includes(result.name) && matchPrevFound== false) {
  32. matchPrevFound = true;
  33. for (i=0; i < leadSources.length; i++) {
  34. sourceField.removeOption(leadSources[i]);
  35. }
  36. }
  37. });
  38. }
  39. }
Add Comment
Please, Sign In to add comment