I have a custom Ribbon button that I want to be enabled based on whether or not the current user is in a specific group.
I can set up a boolean variable that will say whether the user is in the right group, which obviously has to be set to false at first, and check the current user's groups through a REST API call. But what if that takes an abnormally long time, maybe a couple seconds, and the user has already clicked on the Items tab in the ribbon that will expose the button. If the EnabledScript check happens at that point, the button will remain disabled, because the variable will still have it's initial false value.
If the REST API response lets me know that the user is in the correct group, how can I then trigger the Ribbon (specifically the Items tab) to re-execute all the EnabledScript validation checks so that my button will become enabled?
For example, if I set my custom action to have:
EnabledScript="javascript:MyNamespace.CheckIfUserInGroup();" and I have the following code:
var MyNamespace = MyNamespace || {}; MyNamespace.UserIsInGroup = false; MyNamespace.CheckIfUserInGroup = function () { if (MyNamespace.UserIsInGroup) { return true; } else { return false; } } $(document).ready(function () { var uri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/currentuser?$select=groups/title&$expand=groups"; $.ajax({ url: uri, method: 'GET', headers: { accept: 'application/json;odata=verbose' } }).then(function (data) { data.d.Groups.results.forEach(function (group) { if (group.Title === 'The Right Group') { MyNamespace.UserIsInGroup = true; // how can I force the Ribbon to revalidate // now that I know the button _should_ be enabled? } }); }).catch(function (err) { console.log(err); MyNamespace.ShowErrorNotification(err); }); }); Is there something in SP.Ribbon, maybe in the SP.Ribbon.PageManager instance, that can do that?