Reputation: 397
I've got a custom entity that needs to only display the Delete button if there are specific values populated in the form. If this was a customized ribbon button, I'd use the Enable Rules
section to call a JavaScript function.
So, I did just that. I hid the System Delete button and created my own. But I don't know how to get the newly created button to call the same function that the original delete button called. Currently, I have the button call a REST function to delete the record, but the UI doesn't automatically refresh like it would when I clicked the System.Delete button.
Is there a system JavaScript method I can call rather than build all this functionality myself?
Upvotes: 0
Views: 1675
Reputation: 213
I think your root problem is how to disable system button. And the good new is that We can do it now, but it's a complicated task in my opinon. Below is detail steps: 1. use ExportXml to export system ribbon files. (sdk\samplecode\cs\client\ribbon\exportribbonxml)
find the right ribbon file. if you want to modify account's ribbon, then you should choose accountRibbon.xml.
open the ribbon file, and find the button definition statements which you want to hiden.
4.Copy those statements into the customizations.xml of your custom entity, and modify it's enablerule.
Below it's a example code, it was able to hiden the new button of custom entity in homepage ribbon.
<CustomAction Id="Mscrm.Form.new_purchaseorder.SaveAndNew.custom" Location="Mscrm.Form.new_purchaseorder.MainTab.Save.Controls._children">
<CommandUIDefinition>
<Button Id="Mscrm.Form.new_purchaseorder.SaveAndNew" ToolTipTitle="$Resources:Mscrm_Form_Other_MainTab_Save_SaveAndNew_ToolTipTitle" ToolTipDescription="$Resources(EntityDisplayName):Ribbon.Tooltip.SaveAndNew" Command="Mscrm.SaveAndNewPrimary.custom" Sequence="40" LabelText="$Resources:Ribbon.Form.MainTab.Save.SaveAndNew" Alt="$Resources:Ribbon.Form.MainTab.Save.SaveAndNew" Image16by16="/_imgs/ribbon/saveandnew16.png" Image32by32="/_imgs/ribbon/saveandnew32.png" TemplateAlias="o2" />
</CommandUIDefinition>
</CustomAction>
<CommandDefinition Id="Mscrm.SaveAndNewPrimary.custom">
<EnableRules>
<EnableRule Id="Mscrm.NewRecordFromGrid.EnableRule1" />
<EnableRule Id="Mscrm.AvailableOnForm" />
<EnableRule Id="Mscrm.CanSavePrimary" />
</EnableRules>
<DisplayRules>
<DisplayRule Id="Mscrm.CreatePrimaryEntityPermission" />
</DisplayRules>
<Actions>
<JavaScriptFunction FunctionName="Mscrm.RibbonActions.saveAndNewForm" Library="/_static/_common/scripts/RibbonActions.js">
<CrmParameter Value="PrimaryControl" />
</JavaScriptFunction>
</Actions>
</CommandDefinition>
<EnableRule Id="Mscrm.NewRecordFromGrid.EnableRule1">
<CustomRule Library="$webresource:new_purchaseorder.js" FunctionName="NewRecordFromGrid_enablerule1" Default="false"></CustomRule>
</EnableRule>
Upvotes: 1