I thought of giving it a try and came up with the below solution. Consider the name of the Boolean Field in the Library/List is BoolField. The following JSOM code will Enable/Disable the Ribbon Button based on the field value. Place the code in a JS file and refer it from ScriptSrc in CustomAction
function EnableDemoButton() {
var context = SP.ClientContext.get_current();
var list;
var selectedItems = SP.ListOperation.Selection.getSelectedItems(context);
if (CountDictionary(selectedItems) == 1) {
var web = context.get_web();
context.load(web);
var listId = SP.ListOperation.Selection.getSelectedList();
list = web.get_lists().getById(listId);
var itemId = selectedItems[0].id;
if (this.currentItem != null) {
if (this.itemIdToCheck != null) {
if (itemId != itemIdToCheck) {
GetItemDetails();
}
}
}
else {
GetItemDetails();
}
return this._boolValue;
}
else
{
return false;
}
function GetItemDetails() {
this.currentItem = list.getItemById(selectedItems[0].id);
context.load(this.currentItem);
context.executeQueryAsync(Function.createDelegate(this, onQuerySuccess), Function.createDelegate(this, onQueryFailed));
}
function onQuerySuccess(sender, args) {
this._boolValue = this.currentItem.get_item('BoolField');
this.itemIdToCheck = this.currentItem.get_id();
RefreshCommandUI();
}
function onQueryFailed(sender, args)
{
alert(args.get_message());
}
}
The EnableDemoButton will need to be called from EnabledScript. The sample CustomAction is as follows:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction Id="Ribbon.Documents.Manage.Demo"
RegistrationId="101"
Location="CommandUI.Ribbon"
RegistrationType="List">
<CommandUIExtension>
<CommandUIDefinitions>
<CommandUIDefinition Location="Ribbon.Documents.Manage.Controls._children">
<Button Id="Ribbon.Documents.Manage.DemoApp"
Alt="Demo Application"
Command="DemoApplication"
LabelText="Demo Application"
Image16by16="/_layouts/images/placeholder32x32.png"
Image32by32="/_layouts/images/placeholder32x32.png"
TemplateAlias="o1"/>
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<CommandUIHandler Command="DemoApplication" CommandAction="javascript:
alert('Hello');
" EnabledScript="javascript:EnableDemoButton();">
</CommandUIHandler>
</CommandUIHandlers>
</CommandUIExtension>
</CustomAction>
<CustomAction Id="ExportVersionHistory.Script"
Location="ScriptLink"
ScriptSrc="/_Layouts/CustomAction/CustomAction.js" />
</Elements>