Sunday, October 7, 2012

How to Override or Hijack System Button in MSCRM

Hope this blog will meet you on your pink of health!

Let us have a look on the CRM Ribbon structure

Why can’t we look it in a OOPs way?
 ApplicationRibbon is the base xml for all entities. It overrides by individual entityribbon.xml. Then we can override it by RibbonDiffXml.
RibbonDiffXML is the only way of supported customization as per our point of action.
So we can override any of the above base xml element if we know its id.
Here is the Thumb Rule!

1.       How do we find the ID and related actions
Simple: Go to..\ sdk\samplecode\cs\client\ribbon\exportribbonxml project and run the project [you can directly use SDK\Resources\ExportedRibbonXml if you don’t have any customization]
Wow! you will see list of XML files under debug\bin folder. Thanks to SDK samples.  There you can see applicationribbon.xml and individual enityRibbon.xml. These are items which we discussed earlier.
Let us assume a scenario now!
We need to change the action of “activate” button in  subgrid of a custom entity named “new_book”. You can do it for Home grid, Form also. Let us make it simple to Subgrid
Step 1:
We need to find out the Id and action under new_bookRibbon.xml
ID’s which I found:
Mscrm.SubGrid.new_book.Activate  -using for subgrid
Mscrm.HomepageGrid.new_book.Activate – using for Main Grid
Mscrm.Form.new_book.Activate – using for form

Let us go for sub grid id
                Copy activate button block and keep it with you

Step 2:
Export your solution [I believe you already have this information from SDK] and open customization.xml and find out the <RibbonDiffXml> tag of entity [here it is new_book]

Add Custom actions.
Main point is you have kept same Id for Button and Custom action.
Include the button tag details which you had copied earlier under CommandUIdefinition

Done!
Now you can decide whatever customer action as you want. As you noticed here I mentioned command id as MyLogic.SubGrid.new_book.Activate.Command. You can decide whatever name you want


So imagine what will happen if somebody click Activate Button.
Yes you are correct!  it will open Google then ….
It is nothing I copied the actual Activate button function from original entityribbon.xml file. You will get it from step 1. Copy MScrm.HomepageGrid.actvate command and find the function for it.
Now you can add n number of actions.

Ofcourse you need to import the solution and check it.
Enjoy!
Hey wait a moment, Can you recollect some of your successful moments in your life. Just imagine that moments for 2 min and go back your work back. I am sure you will do magic.
Yes definitely I would like to see some nice findings from you as well.
Thanks S.


No comments: