none
Show/Hide "Deactivate" button on the Ribbon based on Security Role for Contact entity without Using JavaScript

    Pergunta

  • Hi,

    I have a situation where i have to hide 'Deactivate' Button based on Security Role. The Deactivate Button in the ribbon control should only be displayed for Certain users who has Some specific Role assigned to. This button should be hidden/disabled for all other Security roles.

    Is it possible to Hide/Show the Ribbon button without using JavaScripts. Can we do it in Simple XML commands.

    Please help me out here.


    Puneet Joshi

    quinta-feira, 23 de fevereiro de 2012 17:51

Respostas

  • Hi Puneet,

    Unfortunately, there is no way of enabling a button based on a user being in a specific role using the ribbon xml alone.

    You have two options:

    Option 1 (uses a javascript webresource). Use a simple javascript function called 'isUserInRole' (example: http://rajeevpentyala.wordpress.com/2011/08/05/check-user-role-in-crm-2011-using-jscript/) and the following ribbon xml:

    <?xml version="1.0" encoding="utf-16"?>
    <RibbonDiffXml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <CustomActions />
      <Templates>
        <RibbonTemplates Id="Mscrm.Templates" />
      </Templates>
      <CommandDefinitions>
        <CommandDefinition Id="Mscrm.HomepageGrid.Deactivate">
          <EnableRules>
            <EnableRule Id="Mscrm.VisualizationPaneNotMaximized" />
            <EnableRule Id="Mscrm.SelectionCountAtLeastOne" />
            <EnableRule Id="new.contact.inrole.EnableRule" />
          </EnableRules>
          <DisplayRules>
            <DisplayRule Id="Mscrm.CanWriteSelected" />
            <DisplayRule Id="Mscrm.SelectedEntityHasStatecode" />
          </DisplayRules>
          <Actions>
            <JavaScriptFunction FunctionName="Mscrm.GridRibbonActions.deactivate" Library="/_static/_common/scripts/RibbonActions.js">
              <CrmParameter Value="SelectedControl" />
              <CrmParameter Value="SelectedControlSelectedItemReferences" />
              <CrmParameter Value="SelectedEntityTypeCode" />
            </JavaScriptFunction>
          </Actions>
        </CommandDefinition>
        <CommandDefinition Id="Mscrm.Form.Deactivate">
          <EnableRules>
            <EnableRule Id="Mscrm.CanWritePrimary" />
            <EnableRule Id="new.contact.inrole.EnableRule" />
          </EnableRules>
          <DisplayRules>
            <DisplayRule Id="Mscrm.CanWritePrimary" />
            <DisplayRule Id="Mscrm.PrimaryIsActive" />
            <DisplayRule Id="Mscrm.PrimaryEntityHasStatecode" />
            <DisplayRule Id="Mscrm.PrimaryIsNotActivity" />
          </DisplayRules>
          <Actions>
            <JavaScriptFunction FunctionName="changeState" Library="/_static/_forms/form.js">
              <StringParameter Value="deactivate" />
              <CrmParameter Value="PrimaryEntityTypeCode" />
              <StringParameter Value="5" />
            </JavaScriptFunction>
          </Actions>
        </CommandDefinition>
      </CommandDefinitions>
      <RuleDefinitions>
        <TabDisplayRules />
        <DisplayRules>
          <DisplayRule Id="Mscrm.CanWriteSelected">
            <EntityPrivilegeRule PrivilegeType="Write" PrivilegeDepth="Basic" AppliesTo="SelectedEntity" />
          </DisplayRule>
          <DisplayRule Id="Mscrm.SelectedEntityHasStatecode">
            <EntityPropertyRule AppliesTo="SelectedEntity" PropertyName="HasStateCode" PropertyValue="true" />
          </DisplayRule>
          <DisplayRule Id="Mscrm.CanWritePrimary">
            <EntityPrivilegeRule PrivilegeType="Write" PrivilegeDepth="Basic" AppliesTo="PrimaryEntity" />
          </DisplayRule>
          <DisplayRule Id="Mscrm.PrimaryIsActive">
            <FormStateRule State="Existing" />
          </DisplayRule>
          <DisplayRule Id="Mscrm.PrimaryEntityHasStatecode">
            <EntityPropertyRule AppliesTo="PrimaryEntity" PropertyName="HasStateCode" PropertyValue="true" />
          </DisplayRule>
          <DisplayRule Id="Mscrm.PrimaryIsNotActivity">
            <EntityPropertyRule AppliesTo="PrimaryEntity" PropertyName="IsActivity" PropertyValue="false" />
          </DisplayRule>
        </DisplayRules>
        <EnableRules>
          <EnableRule Id="Mscrm.VisualizationPaneNotMaximized">
            <CustomRule FunctionName="Mscrm.RibbonActions.disableButtonsWhenChartMaximized" Library="/_static/_common/scripts/RibbonActions.js">
              <CrmParameter Value="SelectedControl" />
            </CustomRule>
          </EnableRule>
          <EnableRule Id="Mscrm.SelectionCountAtLeastOne">
            <SelectionCountRule AppliesTo="SelectedEntity" Minimum="1" />
          </EnableRule>
          <EnableRule Id="new.contact.inrole.EnableRule">
            <CustomRule FunctionName="isUserInRole" Library="$webresource:new_IsUserInRole.js">
              <StringParameter Value="SomeRole" />
            </CustomRule>
          </EnableRule>
          <EnableRule Id="Mscrm.CanWritePrimary">
            <RecordPrivilegeRule PrivilegeType="Write" AppliesTo="PrimaryEntity" />
          </EnableRule>
        </EnableRules>
      </RuleDefinitions>
      <LocLabels />
    </RibbonDiffXml>

    You'll need to change the role name to whatever you need. You'll also need a webresource named new_isUserInRole.js, with a function

    function isUserInRole(rolename)
    {
    ...
    }
    See http://rajeevpentyala.wordpress.com/2011/08/05/check-user-role-in-crm-2011-using-jscript/ for an example of how this function might look.


    Option 2. Create a 'dummy' entity and only set a privilege (e.g. create) for the role you want to detect, and then use a MiscellaneousPrivilegeRule to detect that privilege. So effectively you would have a role based rule - but via the privilege on the dummy entity. Using this technique however would only allow you to show/hide the button, not enable/disable since the MiscellaneousPrivilegeRule is only available on the DisplayRules. The ribobn xml would look like:

    <RibbonDiffXml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <CustomActions />
      <Templates>
        <RibbonTemplates Id="Mscrm.Templates" />
      </Templates>
      <CommandDefinitions>
        <CommandDefinition Id="Mscrm.HomepageGrid.Deactivate">
          <EnableRules>
            <EnableRule Id="Mscrm.VisualizationPaneNotMaximized" />
            <EnableRule Id="Mscrm.SelectionCountAtLeastOne" />
          </EnableRules>
          <DisplayRules>
            <DisplayRule Id="Mscrm.CanWriteSelected" />
            <DisplayRule Id="Mscrm.SelectedEntityHasStatecode" />
            <DisplayRule Id="new.contact.inrole.DisplayRule" />
          </DisplayRules>
          <Actions>
            <JavaScriptFunction FunctionName="Mscrm.GridRibbonActions.deactivate" Library="/_static/_common/scripts/RibbonActions.js">
              <CrmParameter Value="SelectedControl" />
              <CrmParameter Value="SelectedControlSelectedItemReferences" />
              <CrmParameter Value="SelectedEntityTypeCode" />
            </JavaScriptFunction>
          </Actions>
        </CommandDefinition>
        <CommandDefinition Id="Mscrm.Form.Deactivate">
          <EnableRules>
            <EnableRule Id="Mscrm.CanWritePrimary" />
          </EnableRules>
          <DisplayRules>
            <DisplayRule Id="Mscrm.CanWritePrimary" />
            <DisplayRule Id="Mscrm.PrimaryIsActive" />
            <DisplayRule Id="Mscrm.PrimaryEntityHasStatecode" />
            <DisplayRule Id="Mscrm.PrimaryIsNotActivity" />
            <DisplayRule Id="new.contact.inrole.DisplayRule" />
          </DisplayRules>
          <Actions>
            <JavaScriptFunction FunctionName="changeState" Library="/_static/_forms/form.js">
              <StringParameter Value="deactivate" />
              <CrmParameter Value="PrimaryEntityTypeCode" />
              <StringParameter Value="5" />
            </JavaScriptFunction>
          </Actions>
        </CommandDefinition>
      </CommandDefinitions>
      <RuleDefinitions>
        <TabDisplayRules />
        <DisplayRules>
          <DisplayRule Id="Mscrm.CanWriteSelected">
            <EntityPrivilegeRule PrivilegeType="Write" PrivilegeDepth="Basic" AppliesTo="SelectedEntity" />
          </DisplayRule>
          <DisplayRule Id="Mscrm.SelectedEntityHasStatecode">
            <EntityPropertyRule AppliesTo="SelectedEntity" PropertyName="HasStateCode" PropertyValue="true" />
          </DisplayRule>
          <DisplayRule Id="Mscrm.CanWritePrimary">
            <EntityPrivilegeRule PrivilegeType="Write" PrivilegeDepth="Basic" AppliesTo="PrimaryEntity" />
          </DisplayRule>
          <DisplayRule Id="Mscrm.PrimaryIsActive">
            <FormStateRule State="Existing" />
          </DisplayRule>
          <DisplayRule Id="Mscrm.PrimaryEntityHasStatecode">
            <EntityPropertyRule AppliesTo="PrimaryEntity" PropertyName="HasStateCode" PropertyValue="true" />
          </DisplayRule>
          <DisplayRule Id="Mscrm.PrimaryIsNotActivity">
            <EntityPropertyRule AppliesTo="PrimaryEntity" PropertyName="IsActivity" PropertyValue="false" />
          </DisplayRule>
          <DisplayRule Id="new.contact.inrole.DisplayRule">
            <MiscellaneousPrivilegeRule PrivilegeName="Createnew_dummy" PrivilegeDepth="Global" />
          </DisplayRule>
        </DisplayRules>
        <EnableRules>
          <EnableRule Id="Mscrm.VisualizationPaneNotMaximized">
            <CustomRule FunctionName="Mscrm.RibbonActions.disableButtonsWhenChartMaximized" Library="/_static/_common/scripts/RibbonActions.js">
              <CrmParameter Value="SelectedControl" />
            </CustomRule>
          </EnableRule>
          <EnableRule Id="Mscrm.SelectionCountAtLeastOne">
            <SelectionCountRule AppliesTo="SelectedEntity" Minimum="1" />
          </EnableRule>
          <EnableRule Id="Mscrm.CanWritePrimary">
            <RecordPrivilegeRule PrivilegeType="Write" AppliesTo="PrimaryEntity" />
          </EnableRule>
        </EnableRules>
      </RuleDefinitions>
      <LocLabels />
    </RibbonDiffXml>


    You'll need to change the Createnew_dummy to the privilege name for your dummy entity.

    I used the Ribbon Workbench for Dynamics CRM 2011 to do these examples (http://www.develop1.net/public/page/Ribbon-Workbench-for-Dynamics-CRM-2011.aspx) - although the current version doesn't allow  MiscellaneousPrivilegeRule for custom entities - so you'll need to manually edit the ribbon diff once created - this feature will be included in the next version.

    Option 1 is the best way - but I realise you said you didn't want to use Javascript - was that more along the lines that you didn't want to use javascript to manipulate the ribbon directly though unsupported DOM modifications? Option 1 and 2 are fully supported customisations.

    hth,

    Scott


    Scott Durow
    Read my blog: www.develop1.net/public
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    • Marcado como Resposta Puneet Joshi quinta-feira, 23 de fevereiro de 2012 19:48
    quinta-feira, 23 de fevereiro de 2012 19:14
    Usuário que responde

Todas as Respostas

  • I did not test it and just studying from sdk, in my opinion, if the MiscellaneousPrivilegeRule could be used for your situation?

    daemon lin

    • Sugerido como Resposta Makarand Keer quinta-feira, 23 de fevereiro de 2012 18:06
    • Não Sugerido como Resposta Puneet Joshi quinta-feira, 6 de junho de 2013 14:47
    quinta-feira, 23 de fevereiro de 2012 17:59
  • Makarand Keer : You proposed Daemon Lin's reply as an Answer, Can you please share your view, if you have something to share like a Sample code or and Article, SDK Quote/Sample.. that would be great.

    I need a direction on implementing this without using Javascript.

    Please let me know if you have any.

    Puneet Joshi

    quinta-feira, 23 de fevereiro de 2012 18:25
  • Hi Puneet,

    Unfortunately, there is no way of enabling a button based on a user being in a specific role using the ribbon xml alone.

    You have two options:

    Option 1 (uses a javascript webresource). Use a simple javascript function called 'isUserInRole' (example: http://rajeevpentyala.wordpress.com/2011/08/05/check-user-role-in-crm-2011-using-jscript/) and the following ribbon xml:

    <?xml version="1.0" encoding="utf-16"?>
    <RibbonDiffXml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <CustomActions />
      <Templates>
        <RibbonTemplates Id="Mscrm.Templates" />
      </Templates>
      <CommandDefinitions>
        <CommandDefinition Id="Mscrm.HomepageGrid.Deactivate">
          <EnableRules>
            <EnableRule Id="Mscrm.VisualizationPaneNotMaximized" />
            <EnableRule Id="Mscrm.SelectionCountAtLeastOne" />
            <EnableRule Id="new.contact.inrole.EnableRule" />
          </EnableRules>
          <DisplayRules>
            <DisplayRule Id="Mscrm.CanWriteSelected" />
            <DisplayRule Id="Mscrm.SelectedEntityHasStatecode" />
          </DisplayRules>
          <Actions>
            <JavaScriptFunction FunctionName="Mscrm.GridRibbonActions.deactivate" Library="/_static/_common/scripts/RibbonActions.js">
              <CrmParameter Value="SelectedControl" />
              <CrmParameter Value="SelectedControlSelectedItemReferences" />
              <CrmParameter Value="SelectedEntityTypeCode" />
            </JavaScriptFunction>
          </Actions>
        </CommandDefinition>
        <CommandDefinition Id="Mscrm.Form.Deactivate">
          <EnableRules>
            <EnableRule Id="Mscrm.CanWritePrimary" />
            <EnableRule Id="new.contact.inrole.EnableRule" />
          </EnableRules>
          <DisplayRules>
            <DisplayRule Id="Mscrm.CanWritePrimary" />
            <DisplayRule Id="Mscrm.PrimaryIsActive" />
            <DisplayRule Id="Mscrm.PrimaryEntityHasStatecode" />
            <DisplayRule Id="Mscrm.PrimaryIsNotActivity" />
          </DisplayRules>
          <Actions>
            <JavaScriptFunction FunctionName="changeState" Library="/_static/_forms/form.js">
              <StringParameter Value="deactivate" />
              <CrmParameter Value="PrimaryEntityTypeCode" />
              <StringParameter Value="5" />
            </JavaScriptFunction>
          </Actions>
        </CommandDefinition>
      </CommandDefinitions>
      <RuleDefinitions>
        <TabDisplayRules />
        <DisplayRules>
          <DisplayRule Id="Mscrm.CanWriteSelected">
            <EntityPrivilegeRule PrivilegeType="Write" PrivilegeDepth="Basic" AppliesTo="SelectedEntity" />
          </DisplayRule>
          <DisplayRule Id="Mscrm.SelectedEntityHasStatecode">
            <EntityPropertyRule AppliesTo="SelectedEntity" PropertyName="HasStateCode" PropertyValue="true" />
          </DisplayRule>
          <DisplayRule Id="Mscrm.CanWritePrimary">
            <EntityPrivilegeRule PrivilegeType="Write" PrivilegeDepth="Basic" AppliesTo="PrimaryEntity" />
          </DisplayRule>
          <DisplayRule Id="Mscrm.PrimaryIsActive">
            <FormStateRule State="Existing" />
          </DisplayRule>
          <DisplayRule Id="Mscrm.PrimaryEntityHasStatecode">
            <EntityPropertyRule AppliesTo="PrimaryEntity" PropertyName="HasStateCode" PropertyValue="true" />
          </DisplayRule>
          <DisplayRule Id="Mscrm.PrimaryIsNotActivity">
            <EntityPropertyRule AppliesTo="PrimaryEntity" PropertyName="IsActivity" PropertyValue="false" />
          </DisplayRule>
        </DisplayRules>
        <EnableRules>
          <EnableRule Id="Mscrm.VisualizationPaneNotMaximized">
            <CustomRule FunctionName="Mscrm.RibbonActions.disableButtonsWhenChartMaximized" Library="/_static/_common/scripts/RibbonActions.js">
              <CrmParameter Value="SelectedControl" />
            </CustomRule>
          </EnableRule>
          <EnableRule Id="Mscrm.SelectionCountAtLeastOne">
            <SelectionCountRule AppliesTo="SelectedEntity" Minimum="1" />
          </EnableRule>
          <EnableRule Id="new.contact.inrole.EnableRule">
            <CustomRule FunctionName="isUserInRole" Library="$webresource:new_IsUserInRole.js">
              <StringParameter Value="SomeRole" />
            </CustomRule>
          </EnableRule>
          <EnableRule Id="Mscrm.CanWritePrimary">
            <RecordPrivilegeRule PrivilegeType="Write" AppliesTo="PrimaryEntity" />
          </EnableRule>
        </EnableRules>
      </RuleDefinitions>
      <LocLabels />
    </RibbonDiffXml>

    You'll need to change the role name to whatever you need. You'll also need a webresource named new_isUserInRole.js, with a function

    function isUserInRole(rolename)
    {
    ...
    }
    See http://rajeevpentyala.wordpress.com/2011/08/05/check-user-role-in-crm-2011-using-jscript/ for an example of how this function might look.


    Option 2. Create a 'dummy' entity and only set a privilege (e.g. create) for the role you want to detect, and then use a MiscellaneousPrivilegeRule to detect that privilege. So effectively you would have a role based rule - but via the privilege on the dummy entity. Using this technique however would only allow you to show/hide the button, not enable/disable since the MiscellaneousPrivilegeRule is only available on the DisplayRules. The ribobn xml would look like:

    <RibbonDiffXml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <CustomActions />
      <Templates>
        <RibbonTemplates Id="Mscrm.Templates" />
      </Templates>
      <CommandDefinitions>
        <CommandDefinition Id="Mscrm.HomepageGrid.Deactivate">
          <EnableRules>
            <EnableRule Id="Mscrm.VisualizationPaneNotMaximized" />
            <EnableRule Id="Mscrm.SelectionCountAtLeastOne" />
          </EnableRules>
          <DisplayRules>
            <DisplayRule Id="Mscrm.CanWriteSelected" />
            <DisplayRule Id="Mscrm.SelectedEntityHasStatecode" />
            <DisplayRule Id="new.contact.inrole.DisplayRule" />
          </DisplayRules>
          <Actions>
            <JavaScriptFunction FunctionName="Mscrm.GridRibbonActions.deactivate" Library="/_static/_common/scripts/RibbonActions.js">
              <CrmParameter Value="SelectedControl" />
              <CrmParameter Value="SelectedControlSelectedItemReferences" />
              <CrmParameter Value="SelectedEntityTypeCode" />
            </JavaScriptFunction>
          </Actions>
        </CommandDefinition>
        <CommandDefinition Id="Mscrm.Form.Deactivate">
          <EnableRules>
            <EnableRule Id="Mscrm.CanWritePrimary" />
          </EnableRules>
          <DisplayRules>
            <DisplayRule Id="Mscrm.CanWritePrimary" />
            <DisplayRule Id="Mscrm.PrimaryIsActive" />
            <DisplayRule Id="Mscrm.PrimaryEntityHasStatecode" />
            <DisplayRule Id="Mscrm.PrimaryIsNotActivity" />
            <DisplayRule Id="new.contact.inrole.DisplayRule" />
          </DisplayRules>
          <Actions>
            <JavaScriptFunction FunctionName="changeState" Library="/_static/_forms/form.js">
              <StringParameter Value="deactivate" />
              <CrmParameter Value="PrimaryEntityTypeCode" />
              <StringParameter Value="5" />
            </JavaScriptFunction>
          </Actions>
        </CommandDefinition>
      </CommandDefinitions>
      <RuleDefinitions>
        <TabDisplayRules />
        <DisplayRules>
          <DisplayRule Id="Mscrm.CanWriteSelected">
            <EntityPrivilegeRule PrivilegeType="Write" PrivilegeDepth="Basic" AppliesTo="SelectedEntity" />
          </DisplayRule>
          <DisplayRule Id="Mscrm.SelectedEntityHasStatecode">
            <EntityPropertyRule AppliesTo="SelectedEntity" PropertyName="HasStateCode" PropertyValue="true" />
          </DisplayRule>
          <DisplayRule Id="Mscrm.CanWritePrimary">
            <EntityPrivilegeRule PrivilegeType="Write" PrivilegeDepth="Basic" AppliesTo="PrimaryEntity" />
          </DisplayRule>
          <DisplayRule Id="Mscrm.PrimaryIsActive">
            <FormStateRule State="Existing" />
          </DisplayRule>
          <DisplayRule Id="Mscrm.PrimaryEntityHasStatecode">
            <EntityPropertyRule AppliesTo="PrimaryEntity" PropertyName="HasStateCode" PropertyValue="true" />
          </DisplayRule>
          <DisplayRule Id="Mscrm.PrimaryIsNotActivity">
            <EntityPropertyRule AppliesTo="PrimaryEntity" PropertyName="IsActivity" PropertyValue="false" />
          </DisplayRule>
          <DisplayRule Id="new.contact.inrole.DisplayRule">
            <MiscellaneousPrivilegeRule PrivilegeName="Createnew_dummy" PrivilegeDepth="Global" />
          </DisplayRule>
        </DisplayRules>
        <EnableRules>
          <EnableRule Id="Mscrm.VisualizationPaneNotMaximized">
            <CustomRule FunctionName="Mscrm.RibbonActions.disableButtonsWhenChartMaximized" Library="/_static/_common/scripts/RibbonActions.js">
              <CrmParameter Value="SelectedControl" />
            </CustomRule>
          </EnableRule>
          <EnableRule Id="Mscrm.SelectionCountAtLeastOne">
            <SelectionCountRule AppliesTo="SelectedEntity" Minimum="1" />
          </EnableRule>
          <EnableRule Id="Mscrm.CanWritePrimary">
            <RecordPrivilegeRule PrivilegeType="Write" AppliesTo="PrimaryEntity" />
          </EnableRule>
        </EnableRules>
      </RuleDefinitions>
      <LocLabels />
    </RibbonDiffXml>


    You'll need to change the Createnew_dummy to the privilege name for your dummy entity.

    I used the Ribbon Workbench for Dynamics CRM 2011 to do these examples (http://www.develop1.net/public/page/Ribbon-Workbench-for-Dynamics-CRM-2011.aspx) - although the current version doesn't allow  MiscellaneousPrivilegeRule for custom entities - so you'll need to manually edit the ribbon diff once created - this feature will be included in the next version.

    Option 1 is the best way - but I realise you said you didn't want to use Javascript - was that more along the lines that you didn't want to use javascript to manipulate the ribbon directly though unsupported DOM modifications? Option 1 and 2 are fully supported customisations.

    hth,

    Scott


    Scott Durow
    Read my blog: www.develop1.net/public
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    • Marcado como Resposta Puneet Joshi quinta-feira, 23 de fevereiro de 2012 19:48
    quinta-feira, 23 de fevereiro de 2012 19:14
    Usuário que responde
  • Thanks Scott,

    Options 2 Seems to viable, Let me try it out and if i find any difficulties, i will post.

    Your post is very descriptive.

    Thanks a lot though, you have been very helpful.


    Puneet Joshi

    quinta-feira, 23 de fevereiro de 2012 19:48
  • Scott,

    How can do that specifically for Accounts ribbon. I exported the customization.xml file of accounts and i find the following :

    <RibbonDiffXml>
            <CustomActions />
            <Templates>
              <RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>
            </Templates>
            <CommandDefinitions />
            <RuleDefinitions>
              <TabDisplayRules />
              <DisplayRules />
              <EnableRules />
            </RuleDefinitions>
            <LocLabels />
          </RibbonDiffXml>

    I believe i do not have to export application ribbon. I created a dummy entity with no permission to that particular role. Now what is the next step to do. I do not find the deactivate button here in the xml file.

    Please help me out.


    Puneet Joshi

    segunda-feira, 27 de fevereiro de 2012 19:52
  • Scott,

    I followed your approach. I created a custom entity and have no permission to delete for that Roles.

    Part of the Accounts Customisation.xml looks like this (Only the ribbon part)

    <RibbonDiffXml>
            <CustomActions />
            <Templates>
              <RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>
            </Templates>
            <CommandDefinitions>
        <CommandDefinition Id="Mscrm.HomepageGrid.account.Deactivate">
          <EnableRules>
            <EnableRule Id="Mscrm.VisualizationPaneNotMaximized" />
            <EnableRule Id="Mscrm.SelectionCountAtLeastOne" />
          </EnableRules>
          <DisplayRules>
            <DisplayRule Id="Mscrm.CanWriteSelected" />
            <DisplayRule Id="Mscrm.SelectedEntityHasStatecode" />
            <DisplayRule Id="new.contact.inrole.DisplayRule" />
          </DisplayRules>
          <Actions>
            <JavaScriptFunction FunctionName="Mscrm.GridRibbonActions.deactivate" Library="/_static/_common/scripts/RibbonActions.js">
              <CrmParameter Value="SelectedControl" />
              <CrmParameter Value="SelectedControlSelectedItemReferences" />
              <CrmParameter Value="SelectedEntityTypeCode" />
            </JavaScriptFunction>
          </Actions>
        </CommandDefinition>
        <CommandDefinition Id="Mscrm.Form.account.Deactivate">
          <EnableRules>
            <EnableRule Id="Mscrm.CanWritePrimary" />
          </EnableRules>
          <DisplayRules>
            <DisplayRule Id="Mscrm.CanWritePrimary" />
            <DisplayRule Id="Mscrm.PrimaryIsActive" />
            <DisplayRule Id="Mscrm.PrimaryEntityHasStatecode" />
            <DisplayRule Id="Mscrm.PrimaryIsNotActivity" />
            <DisplayRule Id="new.contact.inrole.DisplayRule" />
          </DisplayRules>
          <Actions>
            <JavaScriptFunction FunctionName="changeState" Library="/_static/_forms/form.js">
              <StringParameter Value="deactivate" />
              <CrmParameter Value="PrimaryEntityTypeCode" />
              <StringParameter Value="5" />
            </JavaScriptFunction>
          </Actions>
        </CommandDefinition>
      </CommandDefinitions>
      <RuleDefinitions>
        <TabDisplayRules />
        <DisplayRules>
          <DisplayRule Id="Mscrm.CanWriteSelected">
            <EntityPrivilegeRule PrivilegeType="Write" PrivilegeDepth="Basic" AppliesTo="SelectedEntity" />
          </DisplayRule>
          <DisplayRule Id="Mscrm.SelectedEntityHasStatecode">
            <EntityPropertyRule AppliesTo="SelectedEntity" PropertyName="HasStateCode" PropertyValue="true" />
          </DisplayRule>
          <DisplayRule Id="Mscrm.CanWritePrimary">
            <EntityPrivilegeRule PrivilegeType="Write" PrivilegeDepth="Basic" AppliesTo="PrimaryEntity" />
          </DisplayRule>
          <DisplayRule Id="Mscrm.PrimaryIsActive">
            <FormStateRule State="Existing" />
          </DisplayRule>
          <DisplayRule Id="Mscrm.PrimaryEntityHasStatecode">
            <EntityPropertyRule AppliesTo="PrimaryEntity" PropertyName="HasStateCode" PropertyValue="true" />
          </DisplayRule>
          <DisplayRule Id="Mscrm.PrimaryIsNotActivity">
            <EntityPropertyRule AppliesTo="PrimaryEntity" PropertyName="IsActivity" PropertyValue="false" />
          </DisplayRule>
          <DisplayRule Id="new.contact.inrole.DisplayRule">
            <EntityPrivilegeRule EntityName="new_securitylink" PrivilegeType="Delete" PrivilegeDepth="Global" />        
          </DisplayRule>
        </DisplayRules>
        <EnableRules>
          <EnableRule Id="Mscrm.VisualizationPaneNotMaximized">
            <CustomRule FunctionName="Mscrm.RibbonActions.disableButtonsWhenChartMaximized" Library="/_static/_common/scripts/RibbonActions.js">
              <CrmParameter Value="SelectedControl" />
            </CustomRule>
          </EnableRule>
          <EnableRule Id="Mscrm.SelectionCountAtLeastOne">
            <SelectionCountRule AppliesTo="SelectedEntity" Minimum="1" />
          </EnableRule>
          <EnableRule Id="Mscrm.CanWritePrimary">
            <RecordPrivilegeRule PrivilegeType="Write" AppliesTo="PrimaryEntity" />
          </EnableRule>
        </EnableRules>
      </RuleDefinitions>
            <LocLabels />
          </RibbonDiffXml>

    I have not defined any Custom Actions and Tab Display Rules. What is am missing here. This piece of code is not working.

    Can you help me out please.


    Puneet Joshi

    terça-feira, 28 de fevereiro de 2012 20:06
  • I'll take a look later today.

    Scott


    Scott Durow
    Read my blog: www.develop1.net/public
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    quarta-feira, 29 de fevereiro de 2012 08:17
    Usuário que responde
  • Issue Resolved.

    See the below in Bold in the Code. Button has a command associated with and it has a ID. We have to override the behavior of this command by writing our own command with the same name. I was giving the CommandDefinition Id different from System. Either Associate a custom command in the button itself and use the same in your command definition or use the command name what button is associated with and override with the your custom command having same ID.

    <RibbonDiffXml>
          <CustomActions>
          <CustomAction Id="Mscrm.Form.account.Deactivate.CustomAction" Location="Mscrm.Form.account.MainTab.Save.Controls._children">
            <CommandUIDefinition>
              <Button Id="Mscrm.Form.account.Deactivate" ToolTipTitle="$Resources:Ribbon.HomepageGrid.account.Record.Status.Deactivate" ToolTipDescription="$Resources(EntityPluralDisplayName):Ribbon.Tooltip.Deactivate" Command="Mscrm.Form.Deactivate" Sequence="60" Alt="$Resources:Ribbon.HomepageGrid.account.Record.Status.Deactivate" LabelText="$Resources:Ribbon.HomepageGrid.account.Record.Status.Deactivate" Image16by16="/_imgs/ribbon/deactivate16.png" Image32by32="/_imgs/ribbon/Deactivate_32.png" TemplateAlias="o2" />
            </CommandUIDefinition>
          </CustomAction>
          <CustomAction Id="Mscrm.HomepageGrid.account.Deactivate.CustomAction" Location="Mscrm.HomepageGrid.account.MainTab.Management.Controls._children">
            <CommandUIDefinition>
              <Button Id="Mscrm.HomepageGrid.account.Deactivate" ToolTipTitle="$Resources:Ribbon.HomepageGrid.account.Record.Status.Deactivate" ToolTipDescription="$Resources(EntityPluralDisplayName):Ribbon.Tooltip.Deactivate" Command="Mscrm.HomepageGrid.Deactivate" Sequence="40" Alt="$Resources:Ribbon.HomepageGrid.account.Record.Status.Deactivate" LabelText="$Resources:Ribbon.HomepageGrid.account.Record.Status.Deactivate" Image16by16="/_imgs/ribbon/deactivate16.png" Image32by32="/_imgs/ribbon/Deactivate_32.png" TemplateAlias="o2" />
            </CommandUIDefinition>
          </CustomAction>
            </CustomActions>
            <Templates>
              <RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>
            </Templates>
            <CommandDefinitions>
            <CommandDefinition Id="Mscrm.HomepageGrid.Deactivate">
          <EnableRules>
            <EnableRule Id="Mscrm.VisualizationPaneNotMaximized" />
            <EnableRule Id="Mscrm.SelectionCountAtLeastOne" />
          </EnableRules>
          <DisplayRules>
            <DisplayRule Id="Mscrm.CanWriteSelected" />
            <DisplayRule Id="Mscrm.SelectedEntityHasStatecode" />
            <DisplayRule Id="myApp.DisplayRule" />
          </DisplayRules>
          <Actions>
            <JavaScriptFunction FunctionName="Mscrm.GridRibbonActions.deactivate" Library="/_static/_common/scripts/RibbonActions.js">
              <CrmParameter Value="SelectedControl" />
              <CrmParameter Value="SelectedControlSelectedItemReferences" />
              <CrmParameter Value="SelectedEntityTypeCode" />
            </JavaScriptFunction>
          </Actions>
        </CommandDefinition>
            <CommandDefinition Id="Mscrm.Form.Deactivate">
          <EnableRules>
            <EnableRule Id="Mscrm.CanWritePrimary" />
          </EnableRules>
          <DisplayRules>
            <DisplayRule Id="Mscrm.CanWritePrimary" />
            <DisplayRule Id="Mscrm.PrimaryIsActive" />
            <DisplayRule Id="Mscrm.PrimaryEntityHasStatecode" />
            <DisplayRule Id="Mscrm.PrimaryIsNotActivity" />
            <DisplayRule Id="myApp.DisplayRule" />
          </DisplayRules>
          <Actions>
            <JavaScriptFunction FunctionName="changeState" Library="/_static/_forms/form.js">
              <StringParameter Value="deactivate" />
              <CrmParameter Value="PrimaryEntityTypeCode" />
              <StringParameter Value="5" />
            </JavaScriptFunction>
          </Actions>
        </CommandDefinition>
      </CommandDefinitions>
      <RuleDefinitions>
        <TabDisplayRules />
        <DisplayRules>
          <DisplayRule Id="Mscrm.CanWriteSelected">
            <EntityPrivilegeRule PrivilegeType="Write" PrivilegeDepth="Basic" AppliesTo="SelectedEntity" />
          </DisplayRule>
          <DisplayRule Id="Mscrm.SelectedEntityHasStatecode">
            <EntityPropertyRule AppliesTo="SelectedEntity" PropertyName="HasStateCode" PropertyValue="true" />
          </DisplayRule>
          <DisplayRule Id="Mscrm.CanWritePrimary">
            <EntityPrivilegeRule PrivilegeType="Write" PrivilegeDepth="Basic" AppliesTo="PrimaryEntity" />
          </DisplayRule>
          <DisplayRule Id="Mscrm.PrimaryIsActive">
            <FormStateRule State="Existing" />
          </DisplayRule>
          <DisplayRule Id="Mscrm.PrimaryEntityHasStatecode">
            <EntityPropertyRule AppliesTo="PrimaryEntity" PropertyName="HasStateCode" PropertyValue="true" />
          </DisplayRule>
          <DisplayRule Id="Mscrm.PrimaryIsNotActivity">
            <EntityPropertyRule AppliesTo="PrimaryEntity" PropertyName="IsActivity" PropertyValue="false" />
          </DisplayRule>
          <DisplayRule Id="myApp.DisplayRule">
                <EntityPrivilegeRule EntityName="systemuser" PrivilegeType="Create" PrivilegeDepth="Global" />        
          </DisplayRule>
        </DisplayRules>
        <EnableRules>
          <EnableRule Id="Mscrm.VisualizationPaneNotMaximized">
            <CustomRule FunctionName="Mscrm.RibbonActions.disableButtonsWhenChartMaximized" Library="/_static/_common/scripts/RibbonActions.js">
              <CrmParameter Value="SelectedControl" />
            </CustomRule>
          </EnableRule>
          <EnableRule Id="Mscrm.SelectionCountAtLeastOne">
            <SelectionCountRule AppliesTo="SelectedEntity" Minimum="1" />
          </EnableRule>
          <EnableRule Id="Mscrm.CanWritePrimary">
            <RecordPrivilegeRule PrivilegeType="Write" AppliesTo="PrimaryEntity" />
          </EnableRule>
        </EnableRules>
      </RuleDefinitions>
            <LocLabels />
          </RibbonDiffXml>

    Thanks Scott.

    You were helpful to me. Thanks again.


    Puneet Joshi

    quarta-feira, 29 de fevereiro de 2012 21:47
  • Hi Puneet,

    I've just used the Ribbon Workbench for CRM2011 to try and re-produce, and the following Ribbon Xml appears to work for me:

    <RibbonDiffXml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <CustomActions />
      <Templates>
        <RibbonTemplates Id="Mscrm.Templates" />
      </Templates>
      <CommandDefinitions>
        <CommandDefinition Id="Mscrm.HomepageGrid.Deactivate">
          <EnableRules>
            <EnableRule Id="Mscrm.VisualizationPaneNotMaximized" />
            <EnableRule Id="Mscrm.SelectionCountAtLeastOne" />
          </EnableRules>
          <DisplayRules>
            <DisplayRule Id="Mscrm.CanWriteSelected" />
            <DisplayRule Id="Mscrm.SelectedEntityHasStatecode" />
            <DisplayRule Id="demo.account.InRole.DisplayRule" />
          </DisplayRules>
          <Actions>
            <JavaScriptFunction FunctionName="Mscrm.GridRibbonActions.deactivate" Library="/_static/_common/scripts/RibbonActions.js">
              <CrmParameter Value="SelectedControl" />
              <CrmParameter Value="SelectedControlSelectedItemReferences" />
              <CrmParameter Value="SelectedEntityTypeCode" />
            </JavaScriptFunction>
          </Actions>
        </CommandDefinition>
        <CommandDefinition Id="Mscrm.Form.Deactivate">
          <EnableRules>
            <EnableRule Id="Mscrm.CanWritePrimary" />
          </EnableRules>
          <DisplayRules>
            <DisplayRule Id="Mscrm.CanWritePrimary" />
            <DisplayRule Id="Mscrm.PrimaryIsActive" />
            <DisplayRule Id="Mscrm.PrimaryEntityHasStatecode" />
            <DisplayRule Id="Mscrm.PrimaryIsNotActivity" />
            <DisplayRule Id="demo.account.InRole.DisplayRule" />
          </DisplayRules>
          <Actions>
            <JavaScriptFunction FunctionName="changeState" Library="/_static/_forms/form.js">
              <StringParameter Value="deactivate" />
              <CrmParameter Value="PrimaryEntityTypeCode" />
              <StringParameter Value="5" />
            </JavaScriptFunction>
          </Actions>
        </CommandDefinition>
      </CommandDefinitions>
      <RuleDefinitions>
        <TabDisplayRules />
        <DisplayRules>
          <DisplayRule Id="demo.account.InRole.DisplayRule">
            <EntityPrivilegeRule PrivilegeType="Delete" PrivilegeDepth="Global" EntityName="demo_securitylink" />
          </DisplayRule>
          <DisplayRule Id="Mscrm.CanWriteSelected">
            <EntityPrivilegeRule PrivilegeType="Write" PrivilegeDepth="Basic" AppliesTo="SelectedEntity" />
          </DisplayRule>
          <DisplayRule Id="Mscrm.SelectedEntityHasStatecode">
            <EntityPropertyRule AppliesTo="SelectedEntity" PropertyName="HasStateCode" PropertyValue="true" />
          </DisplayRule>
          <DisplayRule Id="Mscrm.CanWritePrimary">
            <EntityPrivilegeRule PrivilegeType="Write" PrivilegeDepth="Basic" AppliesTo="PrimaryEntity" />
          </DisplayRule>
          <DisplayRule Id="Mscrm.PrimaryIsActive">
            <FormStateRule State="Existing" />
          </DisplayRule>
          <DisplayRule Id="Mscrm.PrimaryEntityHasStatecode">
            <EntityPropertyRule AppliesTo="PrimaryEntity" PropertyName="HasStateCode" PropertyValue="true" />
          </DisplayRule>
          <DisplayRule Id="Mscrm.PrimaryIsNotActivity">
            <EntityPropertyRule AppliesTo="PrimaryEntity" PropertyName="IsActivity" PropertyValue="false" />
          </DisplayRule>
        </DisplayRules>
        <EnableRules>
          <EnableRule Id="Mscrm.SelectionCountAtLeastOne">
            <SelectionCountRule AppliesTo="SelectedEntity" Minimum="1" />
          </EnableRule>
          <EnableRule Id="Mscrm.VisualizationPaneNotMaximized">
            <CustomRule FunctionName="Mscrm.RibbonActions.disableButtonsWhenChartMaximized" Library="/_static/_common/scripts/RibbonActions.js">
              <CrmParameter Value="SelectedControl" />
            </CustomRule>
          </EnableRule>
          <EnableRule Id="Mscrm.CanWritePrimary">
            <RecordPrivilegeRule PrivilegeType="Write" AppliesTo="PrimaryEntity" />
          </EnableRule>
        </EnableRules>
      </RuleDefinitions>
      <LocLabels />
    </RibbonDiffXml>
    Note: This is hiding the HomePage *and* the form de-activate button.

    hth,

    Scott


    Scott Durow
    Read my blog: www.develop1.net/public
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    quarta-feira, 29 de fevereiro de 2012 22:11
    Usuário que responde
  • Scott,

    You've been doing great in this forum.

    Please email me. It's edprice at Microsoft. Thanks!


    Ed Price (a.k.a User Ed), SQL Server Customer Program Manager (Blog, Twitter, Wiki)

    quarta-feira, 3 de outubro de 2012 23:54