IronLionZion
IronLionZion

Reputation: 123

OfficeJS - Retrieving document ID

We need to retrieve an ID that uniquely identifies a document, so that when a user opens the same document in different sessions (even a year apart) we can identify this in the logs.

In the API I found DocumentURL but this could change (if the document is moved?) and it might even be empty (if the document is never stored online?). We could hash a combination of properties like Author and Date Created but these too can change and thus can't be fully relied upon.

How do we access the ID of a document? Ideally we're looking for a solution that works for any type of document, but if currently there is only such a property for a Word document then that is sufficient as well.

EDIT: Adding scenarios that need to work because otherwise my request seems too simple (hence the down-votes?):

  1. The user can open, edit, save, etc. other documents and the ID should ALWAYS be the same PER document. Similarly, if a user shares a document with someone else, the ID read by the other user (when running our add-in) should be the same as for the owner of that document.

  2. The add-in needs to be portable and usable on multiple platforms. When a user opens the same document on Word Online and Win 32, on different computers, etc. the ID must always be the same for that document.

Upvotes: 2

Views: 925

Answers (1)

Rick Kirkham
Rick Kirkham

Reputation: 9684

To create a unique ID, it takes only a little JavaScript to create a GUID. See this SO post for example: Create GUID/UUID in JavaScript

To store the ID, you could use a custom setting or custom property. See Persist State and Settings

Upvotes: 4

Related Questions