Search code examples
dialogword-web-addins

Word web add in using dialog box


I know that the dynamic ribbon buttons or menus does not supported on Web Add in projects yet,and wonder if any improvements has been made about this . In fact, my main problem is : I'm trying to run my web Add in on a Dialog Box, not in the task pane but when I try to get custom properties of an Office Word document, I am able to do this from task pane but can't do the same on Dialog Box. When I try the code below I get a RichApi.Error:AccessDenied. I've checked the domains but could not find any problem. Any suggestions?`

    async function readCustomDocumentProperties5() {
            await Word.run(async (context) => {
                let properties = context.document.properties.customProperties;
                properties.load("key,type,value");


                await context.sync();

                for (var i = 0; i < properties.items.length; i++)
                    console.log(
                        "Property Name:" +
                        properties.items[i].key +
                        "; Type=" +
                        properties.items[i].type +
                        "; Property Value=" +
                        properties.items[i].value
                    );
          
            });
        }

The error:

Uncaught (in promise) RichApi.Error: AccessDenied
at new n (word-win32-16.01.js:26)
at n.i.processRequestExecutorResponseMessage (word-win32-16.01.js:26)
at word-win32-16.01.js:26
at async Dialog.html?_host_Info=Word$Win32$16.01$tr-TR$telemetry$isDialog$$0:47
at async readCustomDocumentProperties5 (Dialog.html?_host_Info=Word$Win32$16.01$tr-TR$telemetry$isDialog$$0:42)

Solution

  • Important: You don't have access to office context in the iframe or new window as dialog. But there is a work-around here.

    You are opening the Dialog from the ribbon using an execute function type. Right?

    The solution is to do the modifications in the functions file where you opened the dialog. With help of Office.context.ui.messageParent(your object as json or whatever you need to pass). So on the button clicks you message the functions file and you have access to the office application context there.