Q:

How to get the SharePoint O365 document ID from an Office Add-in

I have a custom PowerPoint Office Add-in hosted in SharePoint Online.  I'm using the JavaScript API to obtain information about the deck, such as the current slide ID.
Office.initialize = function (reason) {
  $(document).ready(function () {
    Office.context.document.addHandlerAsync('documentSelectionChanged', onDocumentSelectionChanged);
      onDocumentSelectionChanged();
    });
};

function onDocumentSelectionChanged() {
  Office.context.document.getSelectedDataAsync(Office.CoercionType.SlideRange,
    function (result) {
      if (result.status === Office.AsyncResultStatus.Succeeded) {
        var slideId = result.value.slides[0].id;
      }
  });
}

I can't find anything in the API to get the ID (guid) of the current SharePoint document.  Is this part of the Office API or can I obtain the ID some other way?

A:

Can't you get it just from the SourceDoc query string property?
You used to be able to pass SourceDoc as a required token parameter to the addin. Now they've moved it to window.name as a json string. So you'll need to do JSON.parse(window.name).xdmInfo and a little extra string manipulation to clean up the URL. It contains the sharepoint url and the GUID of the document within sharepoint

