OfficeDev / office-js

A repo and NPM package for Office.js, corresponding to a copy of what gets published to the official "evergreen" Office.js CDN, at https://appsforoffice.microsoft.com/lib/1/hosted/office.js.
https://learn.microsoft.com/javascript/api/overview
Other
687 stars 94 forks source link

Enable/Disable Add-in Ribbon Commands #1101

Closed Murugananths closed 4 years ago

Murugananths commented 4 years ago

PLEASE POST QUESTIONS ON STACK OVERFLOW <<<

Hi Team, For disabling the custom ribbon commands tried below things as per the below article but still not achieving the feature. Hence kindly confirm is there any steps missing or any need to wait for stabled release since these are in preview it seems...

In Manifest: Added Enabled to false below Action tab as per document.

note : It is implemented and tested in Office Online Excel... Article Referred: https://docs.microsoft.com/en-us/office/dev/add-ins/design/disable-add-in-commands

Murugananths commented 4 years ago

Hi. Sample examples will be helpful for real time implementation. Thanks.

Murugananths commented 4 years ago

Hi Team,

We were able to disable custom ribbon command initial load but not sure how to enable the same based on click event of other ribbon command event. Gone through below article also but not understanding where to call the method enableButton(). Can you please provide simple examples for one event with manifest configuration.

function enableButton() { Office.ribbon.requestUpdate({ tabs: [ { id: "OfficeAppTab1", controls: [ { id: "MyButton", enabled: true } ]} ]}); }

Murugananths commented 4 years ago

Hi team, Any update please?

Murugananths commented 4 years ago

Hi team, Any update please? We are in middle of developing this feature hence reply will be helpful to proceed further.

Murugananths commented 4 years ago

Hi Team,

We are getting below runtime issue when trying to enable ribbon command with below code tried in page load..

Tried code: Office.ribbon.requestUpdate({ tabs: [ { id: "OfficeAppTab1", controls: [ { id: "MyButton", enabled: true } ]} ]}); Issue : RichApi.Error: The API you are trying to use is not available. It may be available in a different scenario.

Murugananths commented 4 years ago

Hi Team,

Have you had chance to look into this.?

Murugananths commented 4 years ago

Tried below sample with configuration in Manifest and getting below exception. 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

Rick-Kirkham commented 4 years ago

This issue is being tracked with a Stack Overflow question which is where it belongs for now. So, I'm closing this issue.

Suchin15 commented 2 years ago

Hello

image I'm facing this issue can anyone help me