1
votes

My office js Word add-in code saves a custom property to the document customproperty collection. The code for saving is as below

    Word.run(function (context) {
        //method accepts property name plus value
        context.document.properties.customProperties.add(propertyname, value);
        return context.sync()
            .then(function () {
                console.log("Property saved");
            })
            .catch (function (e) {
            console.log("Error occured inserting property " + e.message);

        });
    });

When I create the document using Office 365 for Windows (Word desktop) and invoke my addin the properties are not getting saved into the custom properties collection. However the properties get saved when the document is created using Office Online. I amended the code to include a document.save but it makes no difference. Is there any limitation with this requirement set in Office 365 for Windows. Im on version Version 1803 (Build 9126.2275 Click-to-Run).

In Office 365 for Windows I can even see the custom property when I click on Info->Properties->AdvancedProperties->Custom. However for some odd reason the custom properties are not getting persisted in the document and when I reopen the document they are missing. This looks like a bug with the API in Office 365 for Windows. When we add a custom property to the collection via code it is not getting saved into the document. Even if we include a document.save before the context call, the custom property is not getting saved into the document property collection via code. So I inserted the custom property into the document via code and then hit the save button on Word menu. However this also did not save the custom property into the document. The only way that I can get the custom property to save into the document is by inserting some text into the document and hitting the save button on the menu.

1
The Office Platform product team uses the OfficeDev/office-js GitHub repository to track/manage issues related to the Office.js APIs. I'd suggest that you report this problem by logging an issue there, and include a link to this Stack Overflow post, so that this post can be updated when the issue is resolved.Kim Brandl
You should be making an edit to your post to add additional details, not putting them in comments. The only time you should be using comments on your own question is if you're responding to someone else who has commented to you first (and even then, most information should be added to the question instead).Ken White

1 Answers

0
votes

Thanks for reporting this issue. I actually tried to repro it on the cited build but I am not able to. There is actually a bug we have right now (knwon issue) that when you save custom doc properties and save the document, the document keeps a dirty state, meaning the user will be prompted to save the document again (even if after creating the properties and saving the doc using the UI).

there is no data loss though, just a pop of a "Want to save changes?" dialog that really does not make sense given the doc was explicitly saved but what i observed is that the even if the user selects to not save on that dialog, the properties are still persisted.