locked
How to add a button that runs javascript to a ribbon RRS feed

  • Question

  • Hello,

    I am looking for an online resource that explains how can I add a button to CRM 2013 (or 2011) that runs a JS function?

    I need to add the button to the areas pointed in the screenshot below:

    Thank you,

    Thursday, October 16, 2014 2:38 AM

Answers

All replies

    • Marked as answer by amx2012 Sunday, October 19, 2014 1:29 AM
    Thursday, October 16, 2014 2:45 AM
  • 1. Install ribbon work bench.

    2. add the required button (on form in your case).

    3. Create a command.

    4. Specify the web resrouce and javascript function name

    5. Specify Visibility (optional)

    I am attaching a pic. I have created clone button and invokes javascript to perform action. Please see below. Let me know if you need any help.

    Thursday, October 16, 2014 2:55 AM
  • Is there any way to do it without ribbon workbench?

    I have an existing solution customization and I need to reverse engineer it. So I need to know where to look at without an external tool. Where the buttons and icons are added? Where the JS ribbon button click event handlers are defined.

    Thank you for help.

    Thursday, October 16, 2014 3:26 AM
  • If you want to do it old style you need to edit the customizations.xml file of your solution.

    Normally to edit the ribbon you create an unmanaged solution with only the entity you want to customize (for example Account if you plan to add/modify/delete a ribbon on account entity).

    After you extract the zip file of the solution, open the customizations.xml file and check for the RibbonDiffXml tag, there you will find the definitions of all the changes to the ribbon (the standard commands are not defined there, only the changes).

    After you are done editing the customizations.xml file, zip again the folder content and import the solution back to crm and publish.


    My blog: www.crmanswers.net - Rockstar 365 Profile

    Thursday, October 16, 2014 4:00 AM
  • Like Guido said, open the customisations.xml, look for section RibbonDiffXml and look for these tags. I have extracted xml specific to my button below.

          <RibbonDiffXml>
    
              <CustomAction Id="rio.Mscrm.Isv.contact.Form.CustomAction" Location="Mscrm.Tabs._children" Sequence="1010">
                <CommandUIDefinition>
                  <Tab Command="Mscrm.Isv.contact.Form" Description="ISV Entity Form" Id="Mscrm.Isv.contact.Form" Sequence="1010" Title="$LocLabels:Mscrm.Isv.contact.Form.Title">               
                    <Groups Id="Mscrm.Isv.contact.Form.Groups">
                      <Group Command="Mscrm.Isv.contact.Form.Group0" Description="$LocLabels:Mscrm.Isv.contact.Form.Group0.Title" Id="Mscrm.Isv.contact.Form.Group0" Sequence="10" Template="Mscrm.Templates.Flexible" Title="$LocLabels:Mscrm.Isv.contact.Form.Group0.Title">
                        <Controls Id="Mscrm.Isv.contact.Form.Group0.Controls">
                          <Button Command="Mscrm.Isv.contact.Form.Group0.Control0" Id="Mscrm.Isv.contact.Form.Group0.Control0" Image32by32="/_imgs/ico_16_merge.gif" Image32by32Class="ms-crm-Upgraded-Ribbon-Image32" Image16by16="/_imgs/ico_16_merge.gif" Image16by16Class="ms-crm-Upgraded-Ribbon-Image16" LabelText="$LocLabels:Mscrm.Isv.contact.Form.Group0.Control0.LabelText" Sequence="10" TemplateAlias="o1" ToolTipTitle="$LocLabels:Mscrm.Isv.contact.Form.Group0.Control0.ToolTipTitle" ToolTipDescription="$LocLabels:Mscrm.Isv.contact.Form.Group0.Control0.ToolTipDescription" />
                        </Controls>
                      </Group>
                    </Groups>
                  </Tab>
                </CommandUIDefinition>
              </CustomAction>
            </CustomActions>
    
            <CommandDefinitions>
              <CommandDefinition Id="Mscrm.Isv.contact.Form.Group0.Control0">
                <EnableRules />
                <DisplayRules>
                  <DisplayRule Id="Mscrm.Isv.contact.Form.Group0.Control0" />
                </DisplayRules>
                <Actions>
                  <JavaScriptFunction FunctionName="cloneEntity" Library="$webresource:Contact_main_library.js" />
                </Actions>
              </CommandDefinition>
            </CommandDefinitions>
    
            <LocLabels>
              <LocLabel Id="Mscrm.Isv.contact.Form.Group0.Control0.LabelText">
                <Titles>
                  <Title description="Clone Entity" languagecode="1033" />
                </Titles>
              </LocLabel>
              <LocLabel Id="Mscrm.Isv.contact.Form.Group0.Control0.ToolTipDescription">
                <Titles>
                  <Title description="Clone this Entity record" languagecode="1033" />
                </Titles>
              </LocLabel>
              <LocLabel Id="Mscrm.Isv.contact.Form.Group0.Control0.ToolTipTitle">
                <Titles>
                  <Title description="Clone Entity" languagecode="1033" />
                </Titles>
              </LocLabel>    
          
          </RibbonDiffXml>

    Thursday, October 16, 2014 4:27 AM
  • Hi,

    You will find this post useful.


    Regards, Saad

    • Marked as answer by amx2012 Sunday, October 19, 2014 1:29 AM
    Thursday, October 16, 2014 4:34 AM