Using insertOoxml to insert a MergeField does not work in Word Online

Jordan Trevino 5 Reputation points
2023-10-06T23:01:54.53+00:00

We are using the "insertOoxml" method to insert an XML node that corresponds to a MailMerge MergeField. It works in the Desktop versions of Word, however, in Word Online we get an alert that says "Inserting" and then another that says "Waiting" (image below). After a few seconds the alert disappears but the MergeField does not appear to be inserted. After hitting enter a few times in the word doc the MergeField eventually appears.

Any help or idea on what's going on would be appreciated.

This is the code we are using for inserting the XML node.

insertTextNewApi(xmlNode) {
    Word.run(function (context) {
      var thisDocument = context.document;
      var mergeField = context.document.getSelection().insertOoxml(xmlNode, Word.InsertLocation.replace);
      mergeField.select("End")
      return context.sync().then(function () {
        console.log("Merge field inserted");
      });
    });
  }

And this is what we get. User's image

User's image

User's image

Microsoft 365 and Office | Office Online Server
Microsoft 365 and Office | Development | Other
0 comments No comments
{count} vote

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.