Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to add buttons to ribbon for a normal list

Posted on 2013-01-08
9
Medium Priority
?
874 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
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
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 2000 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

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…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Integration Management Part 2
Suggested Courses

972 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