3

I am trying to hide my SAVE vanilla button according to form state. when the form state != create the vanilla button should not display. I tried different things but nothing works:

  1. I create a function in js that returns true if form is create state

    function isHideState(){
    formstate = Xrm.Page.ui.getFormType();
    if(formstate == formType.create){
    return true;}
    else{
    return false;}
    }
    
  2. I added a disply rule and connected it to my command that relevant to the js function : my rule is : FormStateRule and state: Create

  3. I connected my command to my vanilla button and yet it display even if the form is'nt in create state.

Am I missing something? it's been hours.. guidance someone?

UPDATE: to be more specific - I need the button to be seen only on create mode.

Damkulul
  • 1,406
  • 2
  • 25
  • 59
  • 1
    Hiding the button won't prevent other ways of saving the record (e.g. the save button in the status bar, or ctrl+s) – jasonscript Jan 08 '18 at 00:33

3 Answers3

2

We do not need to use JavaScript here, instead of Display rule, please use Enable/Disable rule and apply the FormState rule. Please see below image enter image description here

1

Note: Whenever you are customizing the vanilla button (OOB Save button in your case), Make sure to start by right click the button in Ribbon workbench & click customize button/command to “retain” the OOB behavior & add your customizations on top of it.

Change this line

if(formstate = formType.create){

into

if(formstate == formType.create){

Single = is for assignment; double = is for comparison.

Update:

RibbonDiffXml follows/expects this structure in command:

<CommandDefinition
Id="String">
 <EnableRules />
 <DisplayRules />
 <Actions />
</CommandDefinition>

There’s no direct property for rules in Button; only command can be linked.

<Button Alt="String"
  Command="String"
  CommandType=["General" | "OptionSelection" | "IgnoredByMenu" ]
  CommandValueId="String"
  Description="String"
  Id="String"
  Image16by16="String"
  Image16by16Class="String"
  Image16by16Left="Non Positive Integer"
  Image16by16Top="Non Positive Integer"
  Image32by32="String"
  Image32by32Class="String"
  Image32by32Left="String"
  Image32by32Top="String"
  LabelCss="String"
  LabelText="String"
  MenuItemId="String"
  ModernCommandType=[ "ControlCommand"| "System"]
  ModernImage=”String”
  Sequence="1"
  TemplateAlias="String"
  ToolTipDescription="String"
  ToolTipHelpKeyWord="String"
  ToolTipImage32by32="String"
  ToolTipImage32by32Class="String"
  ToolTipImage32by32Left="Non Positive Integer"
  ToolTipImage32by32Top="Non Positive Integer"
  ToolTipShortcutKey="String"
  ToolTipTitle="String"
/>

After 2013, commandbar introduction changed the behavior of Enable rule similar to Display rule. Disabled buttons using Enable rule will hide the button to utilize the space for other buttons in command bar (as there are always limitation like 7 or 9 buttons in command bar unlike Ribbon).

Enabling buttons again will act like show/hide once switched (similar to Display rule). Probably you can follow this blogpost to achieve yours.

An important thing to remember is to add the enable rule(s) to the command. This is commonly missed, someone creates an enable rule but forgets to add it to the button command.

If you forget to add enable rules to the command then the button will show on all states/stages of the form. If you forget to add the command to the button, then the button will not show up on the form.

Community
  • 1
  • 1
  • it was == (I updated my question) Still my button is displays should I ho to customization and not use these rules on vanilla buttons? – Damkulul Jan 08 '18 at 08:49
  • @Damkulul did you right click the button in ribbon workbench & clicked customize button/command before doing customization in vanilla button? – Arun Vinoth-Precog Tech - MVP Jan 08 '18 at 11:06
  • 1
    OMG that what was missing! and to create a connection between my display rule to my button should I create a specific command and connect it to a js function? or is there a way to connect the display rule directly to save button? – Damkulul Jan 08 '18 at 16:54
  • 1
    thanks Arun you answer is accurate,my prob was not knowing about **customize command** of vanilla button that was the missing part. – Damkulul Jan 09 '18 at 09:46
1

In the ribbon editor, you can add Display and Enable rules. You can check the form type with no code. Look at this video:

https://www.youtube.com/watch?v=xyLzEAW0CJs

Nick
  • 735
  • 5
  • 14