To add/ Hide buttons I need to modify the ribbon. In order to modify the ribbon it is needed to import the customization of particular entity. For clarity I will mention below steps;
Create solution and add only the entity we need to modify the ribbon.
- Export it (Don’t add any other depending objects/ export as unmanaged solution)
- Unzip the file (it will give three XML files)
- Modify the customizations.xml file accordingly (which we will discuss)
- Zip the files again
- Import the file and publish
- Costomization.xml (TO MODIFY)
- <entityname>
ribbon.xml (TO REFER)
Buttons can be placed in three main ways in ribbon.
Mscrm.Form.<entityname>
Mscrm.HomepageGrid.<entityname>
Mscrm.SubGrid.<entityname>
Now adding below entries within the <CustomActions>
<HideCustomAction Location="Mscrm.Form.opportunity.Recalculate" HideActionId="Mscrm.Form.opportunity.Recalculate.HideAction" /> <HideCustomAction Location="Mscrm.HomepageGrid.opportunity.Recalculate" HideActionId="Mscrm.HomepageGrid.opportunity.Recalculate.HideAction" />
Now I am trying to add my own button with instructions to fire my javascript method. Add below entry within <CustomActions> and <CommandDefinitions>
<CustomAction Id="CA_CUSTOM_Recalculation" Location="Mscrm.Form.opportunity.MainTab.Actions.Controls._children" Sequence="8"> <CommandUIDefinition> <Button Id="B_CUSTOM_Recalculation" Command="Cmd_CUSTOM_Recalculation" LabelText="Recalculate Job" ToolTipTitle="Recalculate Totals, Costs and Margin" ToolTipDescription="This recalculates Job Price, Job Cost and Job Margin" TemplateAlias="o1" Image16by16="/_imgs/SFA/Recalculate_16.png" Image32by32="/_imgs/ribbon/recalculateopportunity32.png"/> </CommandUIDefinition> </CustomAction> <CommandDefinition Id="Cmd_CUSTOM_Recalculation"> <EnableRules> <EnableRule Id="Mscrm.CanWritePrimary" /> <EnableRule Id="Mscrm.OpportunityIsOpen" /> </EnableRules> <DisplayRules> <DisplayRule Id="Mscrm.CanWriteOpportunity" /> </DisplayRules> <Actions> <JavaScriptFunction Library="$webresource:new_recalculations.js" FunctionName="JobCalculationSinglejob"> </JavaScriptFunction> </Actions> </CommandDefinition>
Here CustomAction Id and Button Id are a two unique values I gave to my Custom Action and Button respectively. If you look carefully, it’s noticeable that I have given a command name and use that when I define the command later on. Though location value is bit tricky, I have checked the reference file and found the location of the existing recalculate buttons for that. “_children” postfix is to tell that button should come under that. Sequence number is a number to arrange the buttons with the existing buttons. Other buttons in same location were having numbers 5, 6 and 7 and I wanted to add my one at the end, which I put 8.
Command definition is used to define the behaviour of my button and it’s obvious to see how it calls a method within the JavaScript which has been saved as a webresource. Also I have done a cunning work here. Since I am going to perform a calculation, I copied (from reference file) the enablerules and displayrules from the rules of existing recalculation button. So my button will behave the same way.
Now I am free to do calculation within my Javascript method with my own rules!
thx for this tip. I need to know how you work with selected opportunity from the grid. How can you read and write data with javascript in an opportunity without open it ?
ReplyDeleteHi Birenens,
DeleteAccording to my example JobCalculationSinglejob(ID) function get fired on click and it get ID which is Guid of selected record.
We can use CRM service in JS. I prefer to use a library called Ascentium CrmService, that gives you easy way of doing all the operations like create, update & etc. This page explaines sample codes. http://www.avanadeblog.com/xrm/2010/05/a-microsoft-dynamics-crm-javascript-sdk-in-celebration-of-an-amazing-year-.html
Please send me an email (sumedha7@gmail.com), so that I can send you the library file you need to use.