2

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.

IronLionZion
  • 123
  • 2
  • 10

1 Answers1

4

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

Rick Kirkham
  • 9,038
  • 1
  • 14
  • 32
  • Thanks for the response. Does persisted storage work across all platforms and access routes for that document? e.g. If that document is opened on Win32 or WAC, or I share it with someone else and they open it, will the stored ID be persisted for all of those cases? – IronLionZion Jan 11 '18 at 15:23
  • 1
    According to the information in the link you were given, yes. In Word it appears it's stored as a Custom Document Property - that travels with the document. BTW it's also accessible through the Word UI, just in case that's important for you... – Cindy Meister Jan 11 '18 at 16:43
  • Thanks! Office documents already have an ID property so I was hoping to use that instead of creating an additional ID, which seems like an unnecessary work-around. I can imagine tons of scenarios that need to identify a document so it would be great if the API could integrate it as well. This will work for now though! – IronLionZion Jan 12 '18 at 12:20