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 Answer 1


This code will give you current selected items:


and this will give you ID of current SPWeb:

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

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):

  <CommandUIHandler Command="MyRibbonCommand" 
    CommandAction="javascript: window.myLib.ribbonClick();" />
  • Couldn't have asked for a better answer, thanks a lot. Nov 12, 2012 at 16:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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