SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 1 down vote accepted

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();" />
share|improve this answer
Couldn't have asked for a better answer, thanks a lot. – JᴀʏMᴇᴇ Nov 12 '12 at 16:09

Your Answer


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.