Monday, February 21, 2011

Adding New Button to Ribbon at form level and grid level for custom entity in CRM2011

Adding New Button to Ribbon at form level and grid level for custom entity in CRM2011


1. Export the solution to which we wants to create custom button
2. Extract the solution and open the "custmizations.xml" file to edit.
3. Find "RibbonDiffXml" tag for the particular custom entity which you want to add button. Now replace the "RibbonDiffXml" tag with the following code, it will adds a button to the chosen entity at grid level and form level.


<RibbonDiffXml>
        <CustomActions>
<!-- This to add button in formlevel after exportdata button , CI_formlevel is any unique Id, sequence Number is the position of the button,75 will shows button before Export Excel,you can find sequence numbers of system buttons in SDK-->
          <CustomAction Id="CI_formlevel" Location="Mscrm.Form.new_entityname.MainTab.ExportData.Controls._children" Sequence="75">
            <CommandUIDefinition>
              <Button Id="B_formbutton" Command="Cmd_JavaScript1" LabelText="Custom Button" ToolTipTitle="My Form Button" ToolTipDescription="Form Level Button" TemplateAlias="o1" Image16by16="$webresource:Icon_imgSmall" Image32by32="$webresource:Icon_imgMedium" />
            </CommandUIDefinition>
          </CustomAction>


<!-- this to add button at gridlevel -->
          <CustomAction Id="CI_Gridlevel" Location="Mscrm.HomepageGrid.new_entityname.MainTab.ExportData.Controls._children" Sequence="75">
            <CommandUIDefinition>
              <Button Id="B_GIncident" Command="Cmd_JavaScript1" LabelText="Grid Button" ToolTipTitle="Grid Button" ToolTipDescription="Grid Level button" TemplateAlias="o1" Image16by16="$webresource:Icon_imgSmall" Image32by32="$webresource:Icon_imgMedium" />
            </CommandUIDefinition>
          </CustomAction>
        </CustomActions>
        <Templates>
          <RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>
        </Templates>
        <CommandDefinitions>
          <CommandDefinition Id="Cmd_JavaScript1">
            <EnableRules>
              <EnableRule Id="Mscrm.Enabled" />
            </EnableRules>
            <DisplayRules />
            <Actions>
<!-- call java script library function -->
              <JavaScriptFunction Library="$webresource:new_jscrlib" FunctionName="myfunction"></JavaScriptFunction>
            </Actions>
          </CommandDefinition>
        </CommandDefinitions>
        <RuleDefinitions>
          <TabDisplayRules />
          <DisplayRules />
          <EnableRules />
        </RuleDefinitions>
        <LocLabels />
      </RibbonDiffXml>


4. Now zip the solution files and import back to CRM. Thats it you can see the custom button at form level and grid level.

7 comments:

  1. Hi..
    Thank a lot for this post.
    It is very clear for beginner like me.
    But I didn2t undestand what I will write to



    instead of Cmd_JavaScript1

    I have a JS file and one method..Will I write my metod name isntead of Cmd_JavaScript1 ?

    Please help me.It is very important for me.

    Thanks.

    ReplyDelete
  2. Hi Huseyin...

    "Cmd_JavaScript1" is the name of the command definition. you can provide any name for this..But both the places you have to give same id, while calling the command and defining the command..

    It's not the function name. In the command definition you have to call the js file with the function name..


    <CommandDefinition Id="Cmd_JavaScript1">
    <EnableRules>
    <EnableRule Id="Mscrm.Enabled" />
    </EnableRules>
    <DisplayRules />
    <Actions>
    <!-- call java script library function -->
    // Here you needs to call you js file and in FunctionName provide your js function.
    <JavaScriptFunction Library="$webresource:new_jscrlib" FunctionName="myfunction"></JavaScriptFunction>
    </Actions>
    </CommandDefinition>

    ReplyDelete
  3. Hi GuruPrasad,

    Thanks a lot for this post.Plz send ur mailid.Some doubt in mscrm5 i will clarify that doubt.

    ReplyDelete
  4. Good work. But in myfunction() haw can we access to the id of the selected record from the grid

    ReplyDelete
  5. Hi Balhinio,

    You need to add CrmParameter=SelectedControlSelectedItemIds xml node into ribbon Actions JavaScriptFunction xml node
    <CommandDefinition Id="Cmd_JavaScript1">
    <EnableRules>
    <EnableRule Id="Mscrm.Enabled" />
    </EnableRules>
    <DisplayRules />
    <Actions>
    <!-- call java script library function -->
    <JavaScriptFunction Library="$webresource:new_jscrlib" FunctionName="myfunction">
    <CrmParameter Value="SelectedControlSelectedItemIds"/></JavaScriptFunction>
    </Actions>
    </CommandDefinition>

    Change the java script function in the following way..

    function myfunction(selectedRecordIds) {

    //selectedRecordIds will recieve all GUIDS in comma seperated

    }

    ReplyDelete