Muruga ananth
Muruga ananth

Reputation: 89

How to Enable/Disable Ribbon Command officejs

We followed below reference regarding enable/diable ribbon command but still not clear with that.

1) We were able disable when add-in runs initially 2) But could not enable one ribbon command based on other command event.

Kindly provide some examples.

Tried below but not sure where to call method enableButton.

const enableButton = async () => {
    const button: Control = {id: "MyButton", enabled: true};
    const parentTab: Tab = {id: "OfficeAddinTab1", controls: [button]};
    const ribbonUpdater: RibbonUpdaterData = { tabs: [parentTab]};
    await Office.ribbon.requestUpdate(ribbonUpdater);
}

@Rick.. Sorry for missing reference. Also the one which you mentioned used as reference and below are our try and exception got. Kindly suggest.

WORD AROUND TRIED:

Office.onReady(async () => {
enableButton();
});
const enableButton = async () => {
var button = {id: "Menu", enabled: true};
var parentTab = {id: "Tab1", controls: [button]};
var ribbonUpdater = { tabs: [parentTab]};
await Office.ribbon.requestUpdate(ribbonUpdater);
}

ISSUE :

1) Uncaught (in promise) RichApi.Error: The API you are trying to use is not available. It may be available in a different scenario. at new c (https://appsforoffice.microsoft.com/lib/1.1/hosted/excel-web-16.00.js:24:293355) at c.f.processRequestExecutorResponseMessage (https://appsforoffice.microsoft.com/lib/1.1/hosted/excel-web-16.00.js:24:354008) at https://appsforoffice.microsoft.com/lib/1.1/hosted/excel-web-16.00.js:24:352113

2) taskpane.js:14734 Uncaught (in promise) RichApi.Error: The API you are trying to use is not available. It may be available in a different scenario. at new c (https://appsforoffice.microsoft.com/lib/beta/hosted/excel-web-16.00.js:24:293355) at c.f.processRequestExecutorResponseMessage (https://appsforoffice.microsoft.com/lib/beta/hosted/excel-web-16.00.js:24:354008) at https://appsforoffice.microsoft.com/lib/beta/hosted/excel-web-16.00.js:24:352113

enter image description here

Upvotes: 1

Views: 1485

Answers (1)

Rick Kirkham
Rick Kirkham

Reputation: 9684

You must use a Shared Runtime as described in Enable and disable add-in commands](https://learn.microsoft.com/en-us/office/dev/add-ins/design/disable-add-in-commands). Here's a sample, shared-runtime-scenario, with a manifest that uses the enable feature.

Upvotes: 1

Related Questions