web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Hide Ribbon Button When the selected opportunity records are closed

(0) ShareShare
ReportReport
Posted on by 277

I have this Ribbon button which enables when 2 records are selected. And clicking on the button will open a new record of another entity and I have also got a OnLoad Jscript for the entity which displays the two Selected Record in 2 lookup fields. 

But now I want to hide the button if one or both the opportunity records are closed.

How can I modify the below JScripts. The below JScript is registered as an Action for the buttons Command. Also another Action which retrieves "sdk.rest". One Enable rule to enable button only when 2 records are selected. 

function OpenBlankUI(selectedIds) {

    var windowOptions = {
        openInNewWindow: true
    };

    var parameters = {};
    parameters["new_name"] = "Merge Opportunity";
    //debugger;

    var opp1OppName = "";
    var opp2OppName = "";
    var loadForm = false;

  
        //first opportunity
        parameters["new_opportunity1"] = selectedIds[0];
     

        ////Second Opportunity
        parameters["new_opportunity2"] = selectedIds[1];
        
        Xrm.Utility.openEntityForm("new_oppdupe", null, parameters, windowOptions);
  
}


*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at
    RE: Hide Ribbon Button When the selected opportunity records are closed

    In your button command, add an Enable Rule that calls a Java function, and pass as parameter the selected Ids, as you have done above.

    In your JavaScript function,

    Loop through the list of selected Ids, and call the webapi on each selected id to get whether the status or statusreason for that record is closed. If you have a closed  status reason, you can exit the loop and return false, so that the button is not being displayed. If none are closed, return true, so that the button will be displayed.

    Hope this helps.

  • Turbo Forms Profile Picture
    277 on at
    RE: Hide Ribbon Button When the selected opportunity records are closed

    Hi Aric

    I could find no other alternative except calling webapi. Any references to get statecode/fieldvalue of selected record using webapi? Thanks in advance.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

#3
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans