Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 25064

How to reference a script in the CustomAction Elements?

$
0
0

Hi

I'm trying to define a custom action in the ribbon for my list. When action gets invoked, I'd like to call my JS code. As long as the JS code is embedded within the CommandAction or EnabledScript attributes - all works fine, but when I try to load it through additional CustomAction element, all I get is blank page.

Here is my Elements.xml:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

  <CustomAction ScriptSrc="Scripts/CustomRibbon.js" Location="ScriptLink" Sequence="1">    
  </CustomAction>
 
  <CustomAction Id="CustomRibbonTab" Location="CommandUI.Ribbon">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition Location="Ribbon.ListItem.New.Controls._children">
          <Button
                 Id="Ribbon.Items.New.RibbonTest1"
                 Alt="Test Button"
                 Sequence="5"
                 Command="Test_Button"
                 LabelText="Click me!"
                 Image32by32="_layouts/15/images/placeholder32x32.png"
                 Image16by16="_layouts/15/images/placeholder16x16.png"
                 TemplateAlias="o1" />
        </CommandUIDefinition>
        <CommandUIDefinition Location="Ribbon.List.ViewFormat.Controls._children">
          <Button
                 Id="Ribbon.Items.New.RibbonTest2"
                 Alt="Test Button"
                 Sequence="5"
                 Command="Test_Button"
                 LabelText="Click me!"
                 Image32by32="_layouts/15/images/placeholder32x32.png"
                 Image16by16="_layouts/15/images/placeholder16x16.png"
                 TemplateAlias="o1"
                                         />
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler Command="Test_Button"
                          CommandAction="javascript:processItem('{ListId}', getItemId());"
                          EnabledScript="javascript:isSingleItemEnabled();">
        </CommandUIHandler>
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>

and here is actual content of JS file

function isSingleItemEnabled() {
    return true;
    //var items = SP.ListOperation.Selection.getSelectedItems();
    //return (items.length == 0);
}

function getItemId() {
    return '1234';
    //return SP.ListOperation.Selection.getSelectedItems()[0].id;
}

function processItem(listId, itemId) {
}

So - nothing fancy. What am I doing wrong?

Greg


Viewing all articles
Browse latest Browse all 25064

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>