SharePoint: Enable/disable ribbon button in SharePoint List Display form

Scenario: Enable/disable ribbon button in SharePoint 2010 List Display form


The ID of the list in display form can be retrieved using _spPageContextInfo.pageListId and this ID can be used to get the details of the list. Given below is a function which check whether versioning is enabled in a list or not and depending on that it enables or disables a button in the ribbon.
function ExportVersionHistoryDisplayFormEnable() {       
    var context = SP.ClientContext.get_current();
    this.list = context.get_web().get_lists().getById(_spPageContextInfo.pageListId);
    if (this.versioningEnabled === undefined) {
        context.load(this.list, 'EnableVersioning');
        context.executeQueryAsync(Function.createDelegate(this, this.listSuccess), Function.createDelegate(this, this.listFailed));
    }
    return this.versioningEnabled;
}

function listSuccess(sender, args) {
    this.versioningEnabled = this.list.get_enableVersioning();
    RefreshCommandUI();
}

function listFailed(sender, args) {
    alert('request failed ' + args.get_message() + 'n' + args.get_stackTrace());
}
The above function can be used in EnabledScript of Custom Action.