Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Hide Ribbon Button When the selected opportunity records are closed

Posted on by 275

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

  • Turbo Forms Profile Picture
    Turbo Forms 275 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.

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 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.

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