OfficeDev / office-js

A repo and NPM package for Office.js, corresponding to a copy of what gets published to the official "evergreen" Office.js CDN, at https://appsforoffice.microsoft.com/lib/1/hosted/office.js.
https://learn.microsoft.com/javascript/api/overview
Other
670 stars 96 forks source link

RichApi.Error - InvalidArgument when call insertField with Word.FieldType.ref in Word Online #3623

Open NataliaKravcheniaTR opened 1 year ago

NataliaKravcheniaTR commented 1 year ago

RichApi.Error - InvalidArgument when call insertField with Word.FieldType.ref in Word Online

Your Environment

Expected behavior

Ref field inserted

Current behavior

Ref field is not inserted. RichApi.Error - InvalidArgument occurs

Steps to reproduce

  1. Open ScriptLab
  2. Import this snippet URL ---> (https://gist.github.com/NataliaKravcheniaTR/707c66ebed1d159d2711b4345c513afe)
  3. Click 'Insert bookmark' and 'Insert ref field' button

Provide additional details

The issue is not reproduced in Desktop version The issue is not reproduced for Word.FieldType.date

Useful logs

{name: "RichApi.Error", code: "InvalidArgument", traceMessages: Array[0], innerError: null, debugInfo: Object…}
name: "RichApi.Error"
code: "InvalidArgument"
traceMessages: Array[0]
innerError: null
debugInfo: Object
code: "InvalidArgument"
message: "The argument you provided is not valid. Check the OfficeExtension.Error.debugInfo for more information."
toString: function toString()
errorLocation: "Range.insertField"
statement: "var insertField = range.insertField(...);"
surroundingStatements: Array[10]
0: "var root = context.root;"
1: "var selection = root.getSelection();"
2: "// Instantiate {selection}"
3: "var range = selection.getRange();"
4: "// Instantiate {range}"
5: "// >>>>>"
6: "var insertField = range.insertField(...);"
7: "// <<<<<"
8: "// Instantiate {insertField}"
9: "insertField.load(["result","code"]);"
fullStatements: Array[1]
httpStatusCode: 400
data: undefined
microsoft-github-policy-service[bot] commented 1 year ago

Thank you for letting us know about this issue. We will take a look shortly. Thanks.

xiaoyuMS commented 1 year ago

Hi @NataliaKravcheniaTR , thanks for reaching us.

In Word online, we now only support these four types of fields: Addin, Date, TOC, Hyperlink.

NataliaKravcheniaTR commented 1 year ago

@xiaoyuMS, thank you! Do we have any alternatives to insert ref fields in Word Online, for example, use insertOoxml?

xiaoyu03 commented 1 year ago

@NataliaKravcheniaTR Currently, I don't know a way to insert the ref field. InsertOoxml() may work, but this API doesn't work well on Word Web.

ZYUN-MSFT commented 1 year ago

Hi @NataliaKravcheniaTR , for this issue you may ask a new feature request to https://techcommunity.microsoft.com/t5/microsoft-365-developer-platform/idb-p/Microsoft365DeveloperPlatform. Feature requests on it are considered when we go through our planning process.

Thanks.