locked
i want to conditionally display ribbon button based on a field value selection, Any help? RRS feed

  • Question

  • I used the following customization code

     <CustomActions>
    <CustomAction Id="Create.CustomAction" Location="Mscrm.Form.incident.MainTab.Collaborate.Controls._children" Sequence="40">
                <CommandUIDefinition>
                  <Button Id="Create.Button" Command="Createin.Command" Sequence="31" TemplateAlias="o1"  LabelText="Create invoice" ToolTipTitle="Create invoice" ToolTipDescription="Creates the invoice"  Image16by16="$webresource:cse_images/createorder16x16.png" Image32by32="$webresource:cse_images/createorder32x32.png" />
                </CommandUIDefinition>
              </CustomAction> </CustomActions> <CommandDefinitions>
              <CommandDefinition Id="Createin.Command">
                <EnableRules>
                <EnableRule Id="Createin.Enabled" >
                 </EnableRule>
                </EnableRules>
                <DisplayRules>
                <DisplayRule Id="Createin.DisplayRule"/>
                </DisplayRules>
                <Actions>
              </Actions>
              </CommandDefinition></CommandDefinitions> <RuleDefinitions>
    <DisplayRules>
                <DisplayRule Id="Createin.DisplayRule">
                  <FormStateRule State="Create" InvertResult="true"></FormStateRule>
    <ValueRule Field="statuscode" Value="4"/>
    <ValueRule Field="statuscode" Value="5"/>
                  
                  
                </DisplayRule> </DisplayRules></RuleDefinitions>

    if the value 4 0r 5 is selected it should display the ribbon button ,if form state is not "Create".

    CRM Field Schemaname->statuscode(case status->Displayname) As follow screenshot

    if case status is "Ready to invoice", it should enable "create invoice" button otherwise   "Create invoice" button should be disabled.

    the following error i am getting


    sathishtech.IT



    • Edited by sathishtech Tuesday, October 9, 2012 10:31 AM error screen added
    Tuesday, October 9, 2012 10:16 AM

Answers

  • Hi,

    I have added Enable Rule but you have to replace the "ValueRule" value with the Actual data value of the field "Ready to invoice".

    I am assuming it 6 for the example below just replace that.

    <CustomActions>
      <CustomAction Id="Create.CustomAction" Location="Mscrm.Form.incident.MainTab.Collaborate.Controls._children" Sequence="40">
        <CommandUIDefinition>
          <Button Id="Create.Button" Command="Createin.Command" Sequence="31" TemplateAlias="o1"  LabelText="Create invoice" ToolTipTitle="Create invoice" ToolTipDescription="Creates the invoice"  Image16by16="$webresource:cse_images/createorder16x16.png" Image32by32="$webresource:cse_images/createorder32x32.png" />
        </CommandUIDefinition>
      </CustomAction>
    </CustomActions>
    <CommandDefinitions>
      <CommandDefinition Id="Createin.Command">
        <EnableRules>
          <EnableRule Id="Createin.EnableRule"/>
        </EnableRules>
        <DisplayRules>
          <DisplayRule Id="Createin.DisplayRule"/>
        </DisplayRules>
        <Actions/>
      </CommandDefinition>
    </CommandDefinitions>
    <RuleDefinitions>
      <DisplayRules>
        <DisplayRule Id="Createin.DisplayRule">
          <FormStateRule State="Create" InvertResult="true"></FormStateRule>
          <OrRule>
            <Or>
              <ValueRule Field="statuscode" Value="4"/>
            </Or>
            <Or>
              <ValueRule Field="statuscode" Value="5"/>
            </Or>
          </OrRule>       
        </DisplayRule>
      </DisplayRules>
      <EnableRules>
        <EnableRule Id="Createin.EnableRule">
          <ValueRule Field="statuscode" Value="6"/>
        </EnableRule>
      </EnableRules>
    </RuleDefinitions>

    Hope this helps,

    Yusuf


    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Thanks and Regards, Mohammad Yusuf Ansari http://microxrm.blogspot.in


    Tuesday, October 9, 2012 1:23 PM

All replies

  • Hi,

    The ID <EnableRule Id="Createin.Enabled" > is pointing nowhere. You need to remove it or create an enablerule for it.

    Or point it at this <EnableRule Id="Mscrm.Enabled" /> instead

    Best regards

    Henrik Skydtsgaard

    Tuesday, October 9, 2012 10:55 AM
  • Hi Satish,

    Try to use following code 

    <CustomActions>
      <CustomAction Id="Create.CustomAction" Location="Mscrm.Form.incident.MainTab.Collaborate.Controls._children" Sequence="40">
        <CommandUIDefinition>
          <Button Id="Create.Button" Command="Createin.Command" Sequence="31" TemplateAlias="o1"  LabelText="Create invoice" ToolTipTitle="Create invoice" ToolTipDescription="Creates the invoice"  Image16by16="$webresource:cse_images/createorder16x16.png" Image32by32="$webresource:cse_images/createorder32x32.png" />
        </CommandUIDefinition>
      </CustomAction>
    </CustomActions>
    <CommandDefinitions>
      <CommandDefinition Id="Createin.Command">
        <EnableRules/>  
        <DisplayRules>
          <DisplayRule Id="Createin.DisplayRule"/>
        </DisplayRules>
        <Actions/>
      </CommandDefinition>
    </CommandDefinitions>
    <RuleDefinitions>
      <DisplayRules>
        <DisplayRule Id="Createin.DisplayRule">
          <FormStateRule State="Create" InvertResult="true"></FormStateRule>
          <OrRule>
            <Or>
              <ValueRule Field="statuscode" Value="4"/>
            </Or>
            <Or>
              <ValueRule Field="statuscode" Value="5"/>
            </Or>
          </OrRule>   
        
        </DisplayRule>
      </DisplayRules>
    </RuleDefinitions>

    Hope this helps,

    Yusuf


    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Thanks and Regards, Mohammad Yusuf Ansari http://microxrm.blogspot.in

    Tuesday, October 9, 2012 12:14 PM

  • after making changes,the button is disabled but 

    the following piece code to enable button ,it's not working

    <OrRule>
            <Or>
              <ValueRule Field="statuscode" Value="4"/>
            </Or>
            <Or>
              <ValueRule Field="statuscode" Value="5"/>
            </Or>
          </OrRule>   


    sathishtech.IT

    Tuesday, October 9, 2012 12:52 PM
  • Hi,

    I have added Enable Rule but you have to replace the "ValueRule" value with the Actual data value of the field "Ready to invoice".

    I am assuming it 6 for the example below just replace that.

    <CustomActions>
      <CustomAction Id="Create.CustomAction" Location="Mscrm.Form.incident.MainTab.Collaborate.Controls._children" Sequence="40">
        <CommandUIDefinition>
          <Button Id="Create.Button" Command="Createin.Command" Sequence="31" TemplateAlias="o1"  LabelText="Create invoice" ToolTipTitle="Create invoice" ToolTipDescription="Creates the invoice"  Image16by16="$webresource:cse_images/createorder16x16.png" Image32by32="$webresource:cse_images/createorder32x32.png" />
        </CommandUIDefinition>
      </CustomAction>
    </CustomActions>
    <CommandDefinitions>
      <CommandDefinition Id="Createin.Command">
        <EnableRules>
          <EnableRule Id="Createin.EnableRule"/>
        </EnableRules>
        <DisplayRules>
          <DisplayRule Id="Createin.DisplayRule"/>
        </DisplayRules>
        <Actions/>
      </CommandDefinition>
    </CommandDefinitions>
    <RuleDefinitions>
      <DisplayRules>
        <DisplayRule Id="Createin.DisplayRule">
          <FormStateRule State="Create" InvertResult="true"></FormStateRule>
          <OrRule>
            <Or>
              <ValueRule Field="statuscode" Value="4"/>
            </Or>
            <Or>
              <ValueRule Field="statuscode" Value="5"/>
            </Or>
          </OrRule>       
        </DisplayRule>
      </DisplayRules>
      <EnableRules>
        <EnableRule Id="Createin.EnableRule">
          <ValueRule Field="statuscode" Value="6"/>
        </EnableRule>
      </EnableRules>
    </RuleDefinitions>

    Hope this helps,

    Yusuf


    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Thanks and Regards, Mohammad Yusuf Ansari http://microxrm.blogspot.in


    Tuesday, October 9, 2012 1:23 PM
  • Thanks  Dude,your reply was very helpful for me,It's woking fine after making the following changes

    <CustomActions>
      <CustomAction Id="Create.CustomAction" Location="Mscrm.Form.incident.MainTab.Collaborate.Controls._children" Sequence="40">
        <CommandUIDefinition>
          <Button Id="Create.Button" Command="Createin.Command" Sequence="31" TemplateAlias="o1"  LabelText="Create invoice" ToolTipTitle="Create invoice" ToolTipDescription="Creates the invoice"  Image16by16="$webresource:cse_images/createorder16x16.png" Image32by32="$webresource:cse_images/createorder32x32.png" />
        </CommandUIDefinition>
      </CustomAction>
    </CustomActions>
    <CommandDefinitions>
      <CommandDefinition Id="Createin.Command">
        <EnableRules>
          <EnableRule Id="Createin.EnableRule"/>
        </EnableRules>
        <DisplayRules>
          
        </DisplayRules>
        <Actions/>
      </CommandDefinition>
    </CommandDefinitions>
    <RuleDefinitions>
      <DisplayRules>
        
        
      </DisplayRules>
      <EnableRules>
        <EnableRule Id="Createin.EnableRule">
    <FormStateRule State="Create" InvertResult="true">
          <ValueRule Field="statuscode" Value="6"/>
        </EnableRule>
      </EnableRules>
    </RuleDefinitions>

    in previous post i used display rule,

    in this post i used enable rule--> to conditionally enable, disable button based on the value change of the "statuscode" field,Your reply helped me a lot dude. 


    sathishtech.IT

    Saturday, October 13, 2012 12:48 PM