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

can anyone help me with the problem:

I have a list external items from my system and i add a custom button on a ribbon. My item has a state and depending on the state my button should be available or not. For ribbon custom actions(my button) availability is set by EnabledScript:

<CommandUIHandler Command="Sample.ButtonCommand.Command" CommandAction="javascript:HelloRibbon('{SiteUrl}')" EnabledScript="javascript:IsFirstEnabled('{SiteUrl}')" />

The problem is in EnabledScript I must have access to selected item fields. I can do that so:

var context = SP.ClientContext.get_current();
var list = context.get_web().get_lists().getByTitle(listName);
var task = list.getItemById(_spGetQueryParam('id'));

But that is ASYNC item retrieving but EnabledScript is synchronous call. How i can access item fields for setting button availability in EnabledScript without async calling?

share|improve this question
up vote 3 down vote accepted

No need to do an async call SP.ListOperation.Selection.getSelectedItems(ctx) should get you all the selected items on the page.

 var ctx = SP.ClientContext.get_current();
 var items = SP.ListOperation.Selection.getSelectedItems(ctx);

 for (var i in items)
   //Do something
share|improve this answer
Hmm, i tried that, but items in collection the only field is setted is 'id'. What's wrong? There is my console output: SP.ListOperation.Selection.getSelectedItems(ctx)[0] Object fsObjType: "0" id: "bk800043009300" __proto: Object ....... – Popov Sergei Feb 5 '13 at 8:45
Yes that method only returns IDs of the selected items. If you want to do any further processing on the items, you will have to do some jQuery manipulations to get the values from the columns in the view. – Vardhaman Deshpande Feb 5 '13 at 9:46
I have little expirience with sharepoint. Can I synchronous retrieve this item with jQoery and how this can be done? – Popov Sergei Feb 5 '13 at 9:49
If you switch on your developer tools, in your html you will see that all the columns in the list view are rendered inside <td> elements on the page. You can use jQuery to pick up these values – Vardhaman Deshpande Feb 5 '13 at 10:42

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.