Solved

How to add buttons to ribbon for a normal list

Posted on 2013-01-08
9
855 Views
Last Modified: 2013-01-09
I have added a custom button to the ribbon in a document library in Sharepoint 2010, using the following lines in elements.xml:
Location="CommandUI.Ribbon.ListView">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition Location="Ribbon.Documents.Manage.Controls._children">

Open in new window

Now, I want to add a button to a normal custom list where there is a tab called Items (not Documents). How can I do that? Changing Ribbon.Documents... to Ribbon.Items... doesn't work.
0
Comment
Question by:kasperEH
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 13

Expert Comment

by:Yagya Shree
ID: 38754224
0
 
LVL 44

Expert Comment

by:Rainer Jeschor
ID: 38754376
Hi,
try
"Ribbon.ListItem.Manage"

A complete overview of standard elements:
http://msdn.microsoft.com/en-us/library/ee537543%28office.14%29.aspx

And one of the best resources on the web in regards to ribbon/customizations:
Chris O`Brian
http://www.sharepointnutsandbolts.com/2010/01/adding-ribbon-items-into-existing.html

HTH
Rainer
0
 

Author Comment

by:kasperEH
ID: 38754498
Hi,

I have tried both "Ribbon.ListItem.Manage" and "Ribbon.ListItem.Manage.Controls._children", but it doesn't seem to work. Even though it looks like it should be here based on the articles you link to. There must be some detail I have overlooked. Any ideas?

Kind regards,
Kasper
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 44

Expert Comment

by:Rainer Jeschor
ID: 38754718
Hi Kasper,

could you perhaps attach the whole elements.xml?
Thanks

KR
Rainer
0
 

Author Comment

by:kasperEH
ID: 38754728
Here it is:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction
   Id="RibbonAlert"
   RegistrationId="101"
   RegistrationType="List"
   Location="CommandUI.Ribbon.ListView">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition Location="Ribbon.ListItem.Manage.Controls._children">
          <Button Id="SampleRibbonCommand"
                  Alt="Shows an alert."
                  Description="Shows an alert, just to make an example."
                  Sequence="5"
                  Command="ShowSampleAlert"
                  Image16by16="/_layouts/images/DeviantPoint.DownloadZip/zip_16x16.png"
                  Image32by32="/_layouts/images/DeviantPoint.DownloadZip/zip_32x32.png"
                  LabelText="Ribbon Like"
                  TemplateAlias="o1" />
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler Command="ShowSampleAlert"
                          EnabledScript="javascript:
                          
                             function checkDocsSelected()
                             {
                               // Check the number of selected items
                               var items = SP.ListOperation.Selection.getSelectedItems();
                               return (items.length >= 1);
                             }
                             checkDocsSelected();"
                          CommandAction="javascript:
                          
                             // Shared variables
                             var ctx;
                             var itemsToLike;
                             var notifyId = '';

                             // Function that archives the selected items
                             function likeDocs() {
                             
                               // Notify the end user about the work in progress
                               this.notifyId = SP.UI.Notify.addNotification('Liking docs...', true);
                          
                               // Get the current ClientContext
                               this.ctx = new SP.ClientContext.get_current();

                               // Get the current Web
                               var web = this.ctx.get_web();

                               // Get the currently selected list
                               var listId = SP.ListOperation.Selection.getSelectedList();
                               var sourceList = web.get_lists().getById(listId);

                               // Get the selected items and like each of them
                               var items = SP.ListOperation.Selection.getSelectedItems(this.ctx);
                               
                               var item;      
                               this.itemsToLike = new Array(items.length);
                               for(var i in items) {
                                 item = items[i];
                                 
                                 // Get each selected item
                                 var listItem = sourceList.getItemById(item.id);
                                 this.itemsToLike.push(listItem);
                                 this.ctx.load(listItem);
                               }
                               
                               // Effectively load items from SharePoint
                               this.ctx.executeQueryAsync(Function.createDelegate(this, onQuerySucceeded), Function.createDelegate(this, onQueryFailed));
                             }
                             
                             // Delegate called when server operation is completed upon success
                             function onQuerySucceeded(sender, args) {
                               // Mark each item as Like
                               var item = null;
                               do {
                                 item = this.itemsToLike.pop();
                                 if (item != null) {
                                   alert(item.get_item('Title'));
                                   item.set_item('Title', 'Like');
                                   item.update();                                  
                                 }
                               } while (item != null);
                               
                               // Effectively update items in SharePoint
                               this.ctx.executeQueryAsync(Function.createDelegate(this, onUpdateSucceeded), Function.createDelegate(this, onQueryFailed));
                             }

                             // Delegate called when server operation is completed upon success
                             function onUpdateSucceeded(sender, args) {
                               SP.UI.Notify.removeNotification(this.notifyId);
                               SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);
                             }
                             
                             // Delegate called when server operation is completed with errors
                             function onQueryFailed(sender, args) {
                               alert('The requested operation failed: ' + args.toString());
                             }

                             likeDocs();" />
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>
</Elements>

Open in new window

0
 
LVL 44

Expert Comment

by:Rainer Jeschor
ID: 38754856
Hi,
just a quick first shot:
Can you change
Location="CommandUI.Ribbon.ListView">

Open in new window

to
Location="CommandUI.Ribbon">

Open in new window

in line 7?

HTH
Rainer
0
 

Author Comment

by:kasperEH
ID: 38754906
I have changed line 7 and I still can't see the button. I would like to have it here:
Screenshot of ribbonIn either the Manage or Actions section.
0
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 500 total points
ID: 38755476
Hi,
it is sooo simple:
List has registrationId 100 (doc libs do have 101).
Therefore just change the RegistrationId to 100 and voila - you should see your action.

HTH
Rainer
0
 

Author Closing Comment

by:kasperEH
ID: 38758007
Thank you very much for your help, Rainer. I finally made it work.
In addition to your line change:

 RegistrationId="100"

- I found out that I could use the following in the location line:
 <CommandUIDefinition Location="Ribbon.ListItem.Actions.Controls._children">

I couldn't get "Ribbon.ListItem.Manage" or "Ribbon.ListItem.Manage.Controls._children" to work.

Best regards,
Kasper
0

Featured Post

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Providing anonymous access to pdf form only - sharepoint 2013 9 99
xml files 7 63
Use Sharepoint 365 to manage team project 2 58
.XSN saves to .XML 3 25
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
In case you ever have to remove a faulty web part from a page , add the following to the end of the page url ?contents=1
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question