none
JS API for Office - Document mode does not update when setting Word document in edit mode RRS feed

  • Question

  • Hi,

    I have a question regarding the behaviour of the Office.context.document.mode property. When I open a Word document in read-only mode document mode is readOnly. When I then click the "Edit Document" button in Word to edit the document, document mode is still readOnly. I would expect it to be readWrite now.

    Any insight on this?

    Best regards,

    Geir Morten Hagen

    Wednesday, November 15, 2017 1:35 PM

Answers

  • Hi Geir Morten Hagen,

    I try to make a test on my side.

    I try to make a test with Read only document but it always returns me "ReadWrite".

    I also try to check first document as read write and then make the document read only but then also it just display "ReadWrite".

    you can check my testing result below.

    looks like "Office.context.document.mode" has some issue or limitation here.

    I suggest you to provide a feedback to Word User Voice regarding this issue.

    Welcome to Word's Suggestion Box!

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, November 21, 2017 6:02 AM
    Moderator

All replies

  • Hi Geir Morten Hagen,

    I can see that first you are opening the document as read only and then try to edit the document.

    you will notice that Addin only get load one time when you open the document.

    so did you try to call the same method again to check the mode? or it is only get called once.

    I suggest you to call that line of code on button click may solve your issue.

    function displayDocumentMode() {
        write(Office.context.document.mode);
    }
    
    // Function that writes to a div with id='message' on the page.
    function write(message){
        document.getElementById('message').innerText += message; 
    }

    you can also try to post your code so that I can see what actually you are doing in your code.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, November 16, 2017 9:21 AM
    Moderator
  • Hi,

    the add-in is running a javascript timer every three seconds that checks the Office.context.document.mode property. When debugging I see that the script is running, but the property value is always readOnly, even after clicking on "Edit document" in Word. Right now the script does the same as the displayDocumentMode function you mentioned. 

    The reason I'm doing this check is because I want to disable the UI in the add-in when the document is in readonly mode and enable the UI when the document is in readWrite mode.

    Best regards,

    Geir Morten Hagen

    Monday, November 20, 2017 8:10 AM
  • Hi Geir Morten Hagen,

    I try to make a test on my side.

    I try to make a test with Read only document but it always returns me "ReadWrite".

    I also try to check first document as read write and then make the document read only but then also it just display "ReadWrite".

    you can check my testing result below.

    looks like "Office.context.document.mode" has some issue or limitation here.

    I suggest you to provide a feedback to Word User Voice regarding this issue.

    Welcome to Word's Suggestion Box!

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, November 21, 2017 6:02 AM
    Moderator
  • I'll provide some feedback on this. Thanks for your help, Deepak!
    Tuesday, November 21, 2017 7:18 AM