Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

In a nutshell - I would like a button somewhere on the ribbon (custom action?) that, when clicked, will form a string which includes the current web's ID and the list item ID.

How do I go about achieving this?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

This code will give you current selected items:

SP.ListOperation.Selection.getSelectedItems();

and this will give you ID of current SPWeb:

var ctx = new SP.ClientContext();
var web = ctx.get_web();
ctx.load(web);
ctx.executeQueryAsync(function() {
  var id = web.get_id().toString();
  console.log(id);
});

When creating Ribbon buttons I usually put these in a separate file and call them from Command, like this (mylib.js):

window.myLib = {
  ribbonClick: function() {
    // Do stuff
  }
};

and then call this from the definition of your custom Ribbon button (Elements.xml):

<CommandUIHandlers>
  <CommandUIHandler Command="MyRibbonCommand" 
    CommandAction="javascript: window.myLib.ribbonClick();" />
</CommandUIHandlers>
share|improve this answer
    
Couldn't have asked for a better answer, thanks a lot. –  DeeMac Nov 12 '12 at 16:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.