1

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?

1 Answer 1

3

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
 }
4
  • 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 ....... Feb 5, 2013 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. Feb 5, 2013 at 9:46
  • I have little expirience with sharepoint. Can I synchronous retrieve this item with jQoery and how this can be done? Feb 5, 2013 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 Feb 5, 2013 at 10:42

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.