Solved

How to add buttons to ribbon for a normal list

Posted on 2013-01-08
9
817 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
  • 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
 
LVL 44

Expert Comment

by:Rainer Jeschor
ID: 38754718
Hi Kasper,

could you perhaps attach the whole elements.xml?
Thanks

KR
Rainer
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

If you create your solutions on SharePoint sooner or later you will come upon a request to set  permissions of the item depending on some of the item's meta-data - the author, people assigned as approvers, divisions, categories etc. The most natu…
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

706 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now