1

How can I change EnabledScript asynchronously? I need this, because EnabledScript depended in my case on some item fields, but I can read them only in async way:

var itemId = SP.ListOperation.Selection.getSelectedItems()[0].id;
var clientContext = SP.ClientContext.get_current();
var list = clientContext.get_web().get_lists().getById(listId);
this.listItem = list.getItemById(itemId);
clientContext.load(this.listItem, 'MyPropertyForDisabling');
clientContext.executeQueryAsync(Function.createDelegate(this, onQuerySucceeded),
                          Function.createDelegate(this, onQueryFailed));

and what I need to do than query's extract data?

function onQuerySucceeded() {
 //change EnabledScript status
}

Thanks!

flag

1 Answer

1

I see you've read the article on the Microsoft SharePoint Team Blog on this topic. I'm not sure I can give you a definitive answer, but here are my thoughts:

  • Effectively it seems you're trying to find how to interact with the ribbon based on client-side code (e.g. Client OM). I also looked at this for quite a long time, and wrote down some thoughts in Customize the ribbon programmatically from web parts and field controls
  • Perhaps you should approach this from another angle. The ribbon framework decides when to call 'EnabledScript' (i.e. based on what the user clicks), so if you can get your client-side code to run in the EnabledScript block, you might be able to achieve what you're trying to do.
link|flag
Chris, thanks! But code in EnabledScript block wait for boolean return in sync way. Variant with sync wrapper (async+while) for return value get the high overhead. Continue research – Vitaly Baum Feb 23 at 16:45
Yes I agree - using the Client OM with it's async model can be difficult in the ribbon framework. In one of my samples on my blog I had to move some Client OM code to ensure it executes and gets the return value before the ribbon framework calls the code which requires it. Fun! – Chris O'Brien - MVP Feb 23 at 17:17
I watched your samples, great work! Interested, what happend if I declare more than one CommandUIHandlers on one command – Vitaly Baum Feb 23 at 18:02
Hmm, I'm not sure! I think they might both get executed, as I think I saw a JavaScript array which holds the command names. Not 100* sure though, you'd have to test. – Chris O'Brien - MVP Feb 23 at 22:11
Chris, I close to the solution, do you know how to get CUI.Controls.Button form Ribbon by id? – Vitaly Baum Feb 27 at 18:24

Your Answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.