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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Hide custom ribbon button on selected business process flow stage

(0) ShareShare
ReportReport
Posted on by 115

I want to hide a custom ribbon button if a certain stage is selected or active in the business process flow . I am able to hide it when the stage is set active but the same doesn't happen when it is selected . Can someone let me know if i am missing something in the code below ?  TIA

function hideButton() {

var activeStage = Xrm.Page.data.process.getActiveStage();

var selectedStage = Xrm.Page.data.process.getSelectedStage();

var activeStageName = activeStage.getName();
var selectedStageName = selectedStage.getName();

if (selectedStageName == "" || activeStageName =="" ) {

return false;
}
else {
return true;
}

}

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi ,

    I am bit confused , seems you may check only selected stage. Is there any specific requirement to check active stage ?

    Could you give some details about your requirement?

    Try to check only selected stage criteria , it will work definitely. Please make sure following -

    >  In ribbon workbench enable rule always do by default visible  = false  and  you may do invert result = false . 

    > Now in your code when you will show the button return true and for hide return false..

    Hope this will helps you.

  • Sumisrinivasan Profile Picture
    115 on at

    Hi Goutam,

    The button is visible by default and the requirement is to hide it when the user selects a particular stage or if that stage is made active . The problem is the button gets hidden when the stage is set active but not when its selected(by selected i mean the user clicking on the stage directly without clicking the next stage arrow to go to the next stage).

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi ,

    I am sorry , still bit doubt  so as per my understanding you want to hide button following case

    => (If Stage is Active ) or ( Stage is selected by click  is not active)

    Hide Button

    then which case the button will show?

  • Sumisrinivasan Profile Picture
    115 on at

    Hi Goutam,

    I want to hide the button in both cases . (this is only for a particular stage in the bpf , the button will be visible for all other stages  )

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi ,

    Thanks for your clarification , please try with this -

    function hideButton() {  
        var selectedStage = Xrm.Page.data.process.getSelectedStage();
        var stageStatus = selectedStage.getStatus();   //active or inactive
        var selectedStageName = selectedStage.getName();
        if (selectedStageName == "STAGE NAME" || stageStatus == "active") {  
            return false;
        }
        else {
            return true;
        }
    }


  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi ,

    Please make sure your condition ,  if you are using OR (||) condition that means all active stage button will hide .

  • Sumisrinivasan Profile Picture
    115 on at

    Thanks for your response . I already tried that , it hides the button for all stages instead of just for one stage

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi ,

    Hi,

    Now I understand why this is not working when you are changing BPF stage , enable rule does not firing thats why its not working.

    So there is one alternative solution like below although this is unsupported but it will work.  Please make sure the button need to show in the ribbon directly instead of fly out or clicking three dot. You can get the buttonid by pressing F12 and select selector select the button. Just register the function (OnloadFunction) in onload event.

    function OnloadFunction() {
        Xrm.Page.data.process.addOnStageSelected(checkSelectedStagechange);
    }
    function checkSelectedStagechange() {
        var selectedStage = Xrm.Page.data.process.getSelectedStage();
        var stageStatus = selectedStage.getStatus();   //active or inactive  
        if (selectedStageName == "STAGE NAME" || stageStatus == "active") {
              var button = window.top.document.getElementById("contact|NoRelationship|Form|solutionprefix.Form.contact.MainTab.buttonname.buttonname"); // You can get this id from F12 , select the button
              if (button != null) {
                  button.style.display = 'none';
              }
              else
              {
                  button.style.display = 'block';
              }
        }
    }


  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    You need to remove the else part which is not require in my code posted above..

    You may also think to add additional field in your form wich you will set onchange of bpf like stage status and stage name. Use same function to I shared last post to set the value.

    Now using ribbon workbench enable rule type :field value rule" based on those field value hide the button.

  • TonyN Profile Picture
    695 on at

    It looks like your code is ok. What is triggering your function?

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans