Solved

How to add buttons to ribbon for a normal list

Posted on 2013-01-08
9
860 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

For SharePoint sites, particularly public-facing ones, there are times when adding JavaScript, Meta Tags, CSS Styles or other content to the page <head> section is more practical than modifying master pages.  For instance, you could add the jQuery l…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

728 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