Sign up ×
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:


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. –  JayMee 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.