Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

Is it possible to only allow certain users to re-open opportunity records after they have been closed? If yes, how?

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Is it possible to only allow certain users to re-open opportunity records after they have been closed?  If yes, how?

Thanks!

  • Suggested answer
    cloflyMao Profile Picture
    cloflyMao 25,198 on at
    RE: Is it possible to only allow certain users to re-open opportunity records after they have been closed? If yes, how?

    Hi Tigiard,

    There is a easy and quick way to do it:

    Create a javascript web resource with code below and fire it at form onLoad event:

    function hideReopen(executionContext) {
    
      // in v8.x
      // var userName = Xrm.Page.context.getUserName();
      // var formType = Xrm.Page.ui.getFormType();
      // if (formType == 3 || formType == 4) {}
    
      // in v9.x
      var formContext = executionContext.getFormContext();
    
      var formType = formContext.ui.getFormType();
    
      if (formType == 3 || formType == 4) {
    
        var userName = Xrm.Utility.getGlobalContext().userSettings.userName;
    
        var allowedUsers = ['Adam', 'Ben'];
    
        if (allowedUsers.indexOf(userName) < 0) {
    
          var cssRules = 'li[aria-label="Reopen Opportunity"] { display: none!important; }';
    
          var styleElement = document.createElement('style');
    
          styleElement.appendChild(document.createTextNode(cssRules));
    
          parent.document.getElementsByTagName('head')[0].appendChild(styleElement);
    
        }
    
      }
    
    }

    Because there is specific attribute for the button container: a li element with aria-label="Reopen Opportunity",

    pastedimage1572418727343v1.png

    thus we could call Xrm.Utility.getGlobalContext().userSettings.userName function to get current user name, 

    while check whether it could match an existing user name item in a users array, then insert a css rule with attribute selector to hide the button.

    (It will only insert css rule on page when the opportunity is closed)

    pastedimage1572424036295v2.png

    Note: 

    1. If you work with commented code, then you could just paste my check function inside if block(remove the original), and fire it at form onLoad event.

    2. If you work with code directly without modification, then you should enable Pass execution .. option for the function.

    pastedimage1572439734335v1.png

    You could also achieve it with Ribbon Workbench, it will totally disable the button when condition not meets,

    but it seems that Re-open button in UCI is hard to locate from my test.

    Regards,

    Clofly

  • Suggested answer
    RE: Is it possible to only allow certain users to re-open opportunity records after they have been closed? If yes, how?

    Yes , its possible ..

    As suggested by Kunal you can write hide/show logic for that button . or any custom java script to validate it by using user security role or any parameter and popup alert on click on that

  • RE: Is it possible to only allow certain users to re-open opportunity records after they have been closed? If yes, how?

    you can Modify the display rule for the button to show only for certain user usualy user of certain business unit  probably by using https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/attributes/getuserprivilege

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