Script Lab logo

Script Lab

Code ● Run ● Share

Script Lab no longer supports the Internet Explorer 11 browser or embedded browser control. Please upgrade to a supported version of Microsoft 365 or open Office on the web in a supported browser.

My Snippets

Choose a snippet that you have saved


My snippets on this computer


Snippets you create get erased if you clear your browser cache. To save snippets permanently, export them from the Share menu.
Custom document properties
Adds and reads custom document properties of different types.
Basic API call (JavaScript)
Performs a basic Word API call using plain JavaScript & Promises.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
$("#number").on("click", () => tryCatch(insertNumericProperty));
$("#string").on("click", () => tryCatch(insertStringProperty));
$("#read").on("click", () => tryCatch(readCustomDocumentProperties));
 
async function insertNumericProperty() {
  await Word.run(async (context) => {
    context.document.properties.customProperties.add("Numeric Property", 1234);
 
    await context.sync();
    console.log("Property added");
  });
}
 
async function insertStringProperty() {
  await Word.run(async (context) => {
    context.document.properties.customProperties.add("String Property", "Hello World!")
      ;
 
    await context.sync();
    console.log("Property added");
  });
}
 
async function readCustomDocumentProperties() {
  await Word.run(async (context) => {
    const properties: Word.CustomPropertyCollection = 
      context.document.properties.customProperties;