title: Office JS - Add customProperty to new document
body: <p>I´m developing an addIn for office (word) and I´m stuck with this problem. I need to assign custom properties to a new document that is going to be opened in a new window/instance.</p>
  
  <p>I´m already using custom properties for documents that are already opened this way:</p>
  
  <pre><code>setProperty(propName, propValue) {
   Word.run(context =&gt; {
    context.document.properties.customProperties.add(propName, propValue);
    return context.sync();
  }).catch(error =&gt; {
    if (error instanceof OfficeExtension.Error) {
      console.log(
        "Error code and message: " + JSON.stringify(error.debugInfo)
      );
     }
   });
  }
  
  getFileOverride(attach, file) {
   self.getDocumentAsBase64(attach.id).then(data =&gt; {
    Word.run(context =&gt; {
      let body = context.document.body;
      body.insertFileFromBase64(data, Word.InsertLocation.replace);
      return context
        .sync()
        .then(() =&gt; {
          self.setProperty("fileId", file.id);
          self.setProperty("attachId", attach.id);
        })
        .then(context.sync)
        .catch(error =&gt; {
          self.updateStatus("Error al obtener el archivo");
          if (error instanceof OfficeExtension.Error) {
            console.log(
              "Error code and message: " + JSON.stringify(error.debugInfo)
            );
          }
        });
    }).catch(error =&gt; {
      if (error instanceof OfficeExtension.Error) {
        console.log(
          "Error code and message: " + JSON.stringify(error.debugInfo)
        );
      }
    });
   });
  }
  </code></pre>
  
  <p>But when I create a new document I don´t know how to achieve this. I´ve tried the following but gives a <em>General Exception</em> error:</p>
  
  <pre><code>getDocumentAsBase64(function(data) {
   Word.run(function(context) {
    var myNewDoc = context.application.createDocument(data);
    context.load(myNewDoc);
  
    return context
      .sync()
      .then(function() {
        myNewDoc.properties.load();
        myNewDoc.properties.customProperties.add("custom", "prop");
        myNewDoc.open();
      })
      .then(context.sync)
      .catch(function(myError) {
        //otherwise we handle the exception here!
        updateStatus(myError.message);
      });
   }).catch(function(myError) {
     updateStatus(myError.message);
   });
  });
  </code></pre>
  
  <p>I've tried making a function similar to <em>setProperty</em> but it doesn't add the properties:</p>
  
  <pre><code>function setExternalProperty(document, propName, propValue) {
   Word.run(context =&gt; {
   document.properties.load();
   document.properties.customProperties.add("custom", "prop");
   return context.sync();
  }).catch(error =&gt; {
    if (error instanceof OfficeExtension.Error) {
     console.log("Error code and message: " + JSON.stringify(error.debugInfo));
    }
   });
  }
  </code></pre>
  
  <p>How can I achieve this?</p>