Issue on Dialog when adding Custom Functions into Office Excel Add-In
We are developing an Excel Add-In of a TaskPanel type, (Typescript).
I need to use a Dialog (using DialogApi) in order to authenticate the user into an Azure B2C service. this part works fine, we use the messages to login and refresh tokens as described here.
Recently we needed to define a couple of CustomFunctions. after this every time I open a Dialog (for login or refresh tokens) we see the exception:
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'register') excel-win32-16.01.js
which leads to this code:
and in the dialog, RichApi is undefined
So, after debugging, researching, reading documentation, seems that the issue is because the SharedRuntime library is not supported in a Dialog, but is obligatory for a CustomFunction.
I made some changes in code and notice that if in the manifest I remove the lines related with CustomFunctions (tags <Requirements>, <Runtimes>and <AllFormFactors> from manifest below), the Dialog works perfect, but my custom functions go away
So, the question is if anyone knows how I should define on the Manifest or in code or somehow tell Office that inside a Dialog do not use SharedRuntime? or how can I have both Dialog and CustomFunctions working properly in the same Add-In?
For my context I need the dialog to get user's authentication token and also need to have the custom functions available for users.
Here is the manifest:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<OfficeApp xmlns="http://schemas.microsoft.com/office/appforoffice/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bt="http://schemas.microsoft.com/office/officeappbasictypes/1.0" xmlns:ov="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="TaskPaneApp">
<Id>08120380-49d2-475d-a11b-1d6463912585</Id>
<Version>1.0.0.1</Version>
<ProviderName>ME</ProviderName>
<DefaultLocale>es-MX</DefaultLocale>
<DisplayName DefaultValue="ME">
</DisplayName>
<Description DefaultValue="ME"/>
<IconUrl DefaultValue="https://localhost:3010/assets/logo-32.png"/>
<HighResolutionIconUrl DefaultValue="https://localhost:3010/assets/logo-64.png"/>
<SupportUrl DefaultValue="https://contenidos.contpaqi.com/"/>
<AppDomains>
<AppDomain>https://localhost:3010</AppDomain>
<AppDomain>https://MY.b2clogin.com/</AppDomain>
<AppDomain>https://My_API.azurewebsites.net</AppDomain>
</AppDomains>
<Hosts>
<Host Name="Workbook"></Host>
</Hosts>
<Requirements>
<Sets DefaultMinVersion="1.9">
<Set Name="ExcelApi" MinVersion="1.9" />
<Set Name="CustomFunctionsRuntime" MinVersion="1.1"/>
<Set Name="SharedRuntime" MinVersion="1.1"/>
</Sets>
</Requirements>
<DefaultSettings>
<SourceLocation DefaultValue="https://localhost:3010/taskpane.html"/>
</DefaultSettings>
<Permissions>ReadWriteDocument</Permissions>
<VersionOverrides xmlns="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="VersionOverridesV1_0">
<Hosts>
<Host xsi:type="Workbook">
<Runtimes>
<Runtime resid="Taskpane.Url" lifetime="long" />
<Runtime resid="Home.Url" lifetime="long" />
<Runtime resid="Functions.Page.Url" lifetime="long" />
</Runtimes>
<AllFormFactors>
<ExtensionPoint xsi:type="CustomFunctions">
<Script>
<SourceLocation resid="Functions.Script.Url" />
</Script>
<Page>
<SourceLocation resid="Functions.Page.Url"/>
</Page>
<Metadata>
<SourceLocation resid="Functions.Metadata.Url" />
</Metadata>
<Namespace resid="Functions.Namespace" />
</ExtensionPoint>
</AllFormFactors>
<DesktopFormFactor>
<GetStarted>
<Title resid="GetStarted.Title"/>
<Description resid="GetStarted.Description"/>
<LearnMoreUrl resid="GetStarted.LearnMoreUrl"/>
</GetStarted>
<FunctionFile resid="Functions.Page.Url"/>
<ExtensionPoint xsi:type="PrimaryCommandSurface">
<OfficeTab id="TabHome">
<Group id="CommandsGroup">
<Label resid="CommandsGroup.Label"/>
<Icon>
<bt:Image size="16" resid="Logo.16x16"/>
<bt:Image size="32" resid="Logo.32x32"/>
<bt:Image size="80" resid="App.Logo"/>
</Icon>
<Control xsi:type="Button" id="TaskpaneButton">
<Label resid="TaskpaneButton.Label"/>
<Supertip>
<Title resid="TaskpaneButton.Label"/>
<Description resid="TaskpaneButton.Tooltip"/>
</Supertip>
<Icon>
<bt:Image size="16" resid="Logo.16x16"/>
<bt:Image size="32" resid="Logo.32x32"/>
<bt:Image size="80" resid="App.Logo"/>
</Icon>
<Action xsi:type="ShowTaskpane">
<TaskpaneId>ButtonId1</TaskpaneId>
<SourceLocation resid="Taskpane.Url"/>
</Action>
</Control>
</Group>
</OfficeTab>
</ExtensionPoint>
</DesktopFormFactor>
</Host>
</Hosts>
<Resources>
<bt:Images>
<bt:Image id="Icon.16x16" DefaultValue="https://localhost:3010/assets/icon-16.png"/>
<bt:Image id="Icon.32x32" DefaultValue="https://localhost:3010/assets/icon-32.png"/>
<bt:Image id="Icon.80x80" DefaultValue="https://localhost:3010/assets/icon-80.png"/>
<bt:Image id="Logo.16x16" DefaultValue="https://localhost:3010/assets/logo-16.png"/>
<bt:Image id="Logo.32x32" DefaultValue="https://localhost:3010/assets/logo-32.png"/>
<bt:Image id="Logo.80x80" DefaultValue="https://localhost:3010/assets/logo-80.png"/>
<bt:Image id="App.Logo" DefaultValue="https://localhost:3010/assets/app-logo.png"/>
</bt:Images>
<bt:Urls>
<bt:Url id="Functions.Script.Url" DefaultValue="https://localhost:3010/functions.bundle.js"/>
<bt:Url id="Functions.Metadata.Url" DefaultValue="https://localhost:3010/functions.json"/>
<bt:Url id="GetStarted.LearnMoreUrl" DefaultValue="https://go.microsoft.com/fwlink/?LinkId=276812"/>
<bt:Url id="Taskpane.Url" DefaultValue="https://localhost:3010/taskpane.html"/>
<bt:Url id="Login.Url" DefaultValue="https://localhost:3010/login.html"/>
<bt:Url id="Functions.Page.Url" DefaultValue="https://localhost:3010/functions.html"/>
<bt:Url id="Home.Url" DefaultValue="https://localhost:3010/home.html"/>
</bt:Urls>
<bt:ShortStrings>
<bt:String id="Functions.Namespace" DefaultValue="CP.FN"/>
<bt:String id="GetStarted.Title" DefaultValue="my super title"/>
<bt:String id="CommandsGroup.Label" DefaultValue="Me"/>
<bt:String id="TaskpaneButton.Label" DefaultValue="My"/>
</bt:ShortStrings>
<bt:LongStrings>
<bt:String id="GetStarted.Description" DefaultValue="panel ready"/>
<bt:String id="TaskpaneButton.Tooltip" DefaultValue="my super tooltip"/>
<bt:String id="residDescription" DefaultValue="my super description"/>
</bt:LongStrings>
</Resources>
</VersionOverrides>
</OfficeApp>