Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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'));
clientContext.load(....);
clientContext.executeQueryAsync(...);

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

1 Answer 1

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 ....... –  Fobos 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? –  Fobos 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

 
discard

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.