{"id":10398,"date":"2022-05-10T12:16:25","date_gmt":"2022-05-10T19:16:25","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/?p=10398"},"modified":"2022-08-04T16:36:48","modified_gmt":"2022-08-04T23:36:48","slug":"announcing-changes-to-office-add-ins-executefunction-commands","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/announcing-changes-to-office-add-ins-executefunction-commands\/","title":{"rendered":"Announcing changes to Office Add-ins&#8217; ExecuteFunction commands"},"content":{"rendered":"<p><span data-contrast=\"auto\">Office Add-ins have long supported custom ribbon buttons and menus, called add-in commands. For Word, Excel, PowerPoint, and Outlook, these come in two flavors: those that open a task pane and those that call a JavaScript function. For the latter <strong>ExecuteFunction<\/strong> type of command, you create a function in a JavaScript file and then identify the function by name in the manifest. The JavaScript file is loaded by a UI-less HTML file, usually called functionfile.html or commands.html.<\/span><\/p>\n<p><span data-contrast=\"auto\">To improve security in Office Add-ins, we are changing how you create <strong>ExecuteFunction<\/strong> add-in commands. <\/span><span data-contrast=\"none\">This change does not require re-submission of your Office Add-in.<\/span><\/p>\n<p><span data-contrast=\"auto\">In addition to defining the JavaScript function, you also need to register the function with Office by adding a call of <code>Office.actions.associate(\"name-of-function\", function)<\/code>.<\/span><\/p>\n<pre class=\"prettyprint\">Office.actions.associate(\"name-of-function\", function)<\/pre>\n<h2><span data-contrast=\"auto\">Office Add-ins ExecuteFunction code sample<\/span><\/h2>\n<pre class=\"prettyprint\"><code class=\"language-Javascript\">function writeText(event) {\r\n    \/\/ Implement your custom code here. The following code is a simple example.   \r\n    Office.context.document.setSelectedDataAsync(\"ExecuteFunction works. Button ID=\" + event.source.id,\r\n        function(asyncResult) {\r\n            var error = asyncResult.error;\r\n            if (asyncResult.status === Office.AsyncResultStatus.Failed) {\r\n                \/\/ Show error message. \r\n            } else {\r\n                \/\/ Show success message. \r\n            }\r\n        });\r\n    \/\/ Calling event.completed is required. event.completed lets the platform know that processing has completed. \r\n    event.completed();\r\n}\r\n\/\/ Register the function with the associate API \r\nOffice.actions.associate(\"writeText\", writeText);\r\n<\/code><\/pre>\n<p><div class=\"alert alert-info\"><p class=\"alert-divider\"><i class=\"fabric-icon fabric-icon--Info\"><\/i><strong>IMPORTANT<\/strong><\/p>You must make these changes before October 30, 2022. On that date, functions in the <strong>ExecuteFunction<\/strong> type add-in commands that are not registered in this way will no longer run. So, lease update your Office Add-in as soon as possible to avoid impacting your add-ins functionality. <\/div><\/p>\n<p><span data-contrast=\"none\">To test that you\u2019ve correctly registered your functions, you can simulate how Office will behave on October 30, 2022. Add an attribute to the &lt;script&gt; tag that loads the Office JavaScript library in the HTML file. The following is an example:\n<\/span><\/p>\n<pre>[html]\r\n&lt;script src=\"https:\/\/appsforoffice.microsoft.com\/lib\/1\/hosted\/office.js\" data-use-associated-actions-only=\"1\" type=\"text\/javascript\"&gt;&lt;\/script&gt;\r\n[html]<\/pre>\n<p><span data-contrast=\"none\">When you load the Office JavaScript library with the data-use-associated-actions-only attribute, registered add-in commands will run. Add-in commands that you do not register with the associated API, will not.<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3>Additional resources<\/h3>\n<ul>\n<li>Find more Office Add-in samples in our <a href=\"https:\/\/github.com\/OfficeDev\/Office-Add-in-samples\/tree\/main\/Samples\/office-add-in-commands\" target=\"_blank\" rel=\"noopener\">GitHub repo<\/a><\/li>\n<li>Learn more about add-in commands, see our <a href=\"https:\/\/docs.microsoft.com\/en-us\/office\/dev\/add-ins\/develop\/create-addin-commands\" target=\"_blank\" rel=\"noopener\">documentation<\/a><\/li>\n<li>Join our monthly <a href=\"https:\/\/aka.ms\/officeaddinscommunitycall\" target=\"_blank\" rel=\"noopener\">Office Add-ins community call<\/a><\/li>\n<li>To report any issues with ExecuteFunction add-in commands, please report them in our <a href=\"https:\/\/github.com\/OfficeDev\/office-js\/issues\" target=\"_blank\" rel=\"noopener\">Github repo<\/a><\/li>\n<li>More Excel developer resources, see <a href=\"https:\/\/developer.microsoft.com\/excel\">Excel Dev Center<\/a><\/li>\n<li>Office Add-ins <a href=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/category\/office-add-ins\/\">blog<\/a><\/li>\n<\/ul>\n<p>Happy coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To improve security in Office Add-ins, we are changing how you create ExecuteFunction add-in commands. <\/p>\n","protected":false},"author":69076,"featured_media":25159,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[11],"tags":[132],"class_list":["post-10398","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-office-add-ins","tag-add-ins"],"acf":[],"blog_post_summary":"<p>To improve security in Office Add-ins, we are changing how you create ExecuteFunction add-in commands. <\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts\/10398","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/users\/69076"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/comments?post=10398"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts\/10398\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/media\/25159"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/media?parent=10398"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/categories?post=10398"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/tags?post=10398"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}