0

I need to create an addin (javascript) for Word that will insert the "Document ID" from sharepoint into the footer of the document.

I've found the _dlc_DocIdItemGuid but I need the _dlc_DocId. I imagine I'm missing some intermediate .load call?

Here's what I have so far:

const setFooter = async () => {
  return Word.run(async context => {
    const doc = context.document;

    // Create a proxy sectionsCollection object.
    const docSections = doc.sections;
    context.load(docSections, "body/style");

    // Load properties
    const builtInProperties = doc.properties;
    builtInProperties.load("*");

    // Load custom properties
    const customProperties = builtInProperties.customProperties;
    customProperties.load("*");
    await context.sync();

    // Create a proxy object the primary footer of the first section.
    const footer = docSections.items[0].getFooter("Primary");

    // Queue a command to replace text in the footer.
    footer.insertText(
      JSON.stringify(doc.toJSON(), null, 2),
      Word.InsertLocation.replace
    );

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    return context.sync();
  });
};

Which inserts something like the following:

{
  "properties": {
    "applicationName": "Microsoft Office Word",
    "author": "John Doe",
    "category": "",
    "comments": "",
    "company": "",
    "creationDate": "2019-04-08T20:14:00.000Z",
    "format": "",
    "keywords": "",
    "lastAuthor": "John Doe",
    "lastPrintDate": null,
    "lastSaveTime": "2019-04-09T12:33:00.000Z",
    "manager": "",
    "revisionNumber": "52",
    "security": 0,
    "subject": "",
    "template": "Normal.dotm",
    "title": "",
    "customProperties": [
      {
        "key": "AuthorIds_UIVersion_512",
        "type": "String",
        "value": "10"
      },
      {
        "key": "ContentTypeId",
        "type": "String",
        "value": "0x0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
      },
      {
        "key": "_dlc_DocIdItemGuid",
        "type": "String",
        "value": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
      },
      {
        "key": "AuthorIds_UIVersion_2560",
        "type": "String",
        "value": "10"
      }
    ]
  },
  "sections": [
    {
      "body": {
        "style": "Normal"
      }
    }
  ]
}

Documentation I've tried:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.