0

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?

1

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>
  • Couldn't have asked for a better answer, thanks a lot. – JᴀʏMᴇᴇ Nov 12 '12 at 16:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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