OfficeDev / office-js

A repository for issues related to the Office JavaScript APIs and Office Add-ins platform. Find the Office.js library in Office.js CDN: https://appsforoffice.microsoft.com/lib/1/hosted/office.js.
https://learn.microsoft.com/javascript/api/overview
Other
725 stars 106 forks source link

Excel and PowerPoint are throwing exceptions when trying to delete custom properties #5503

Open matheushoeltgebaum opened 1 month ago

matheushoeltgebaum commented 1 month ago

Provide required information needed to triage your issue

Your Environment

Expected behavior

When trying to iterate over and delete custom properties from the document that met a certain condition, it should delete the properties.

Current behavior

In Excel and PowerPoint APIs, I am loading the custom properties, by calling the load function with the parameter "items/key". Then, I iterate through the items and check if the property key meets a condition. If it does, I call the delete function. Otherwise, I do nothing.

When I execute the code as mentioned above, it throws exceptions, for both Excel and PowerPoint.

As I execute the same code with the Word API, it works, no exceptions are thrown.

Steps to reproduce

For Excel:

  1. Open Excel
  2. Install the ScriptLab add-in
  3. Import the Excel snippet, available in this issue
  4. Run the snippet
  5. Click in the button "Set custom property"
  6. Click in the button "Get custom property"
  7. Click in the button "Delete custom property"

For PowerPoint:

  1. Open PowerPoint
  2. Install the ScriptLab add-in
  3. Import the PowerPoint snippet, available in this issue
  4. Run the snippet
  5. Click in the button "Set custom property"
  6. Click in the button "Get custom property"
  7. Click in the button "Delete custom property"

Provide additional details

  1. As a workaround to this issue, in both snippets, I created the button "Delete custom property (Workaround)", to delete the custom property.

Link to live example(s)

  1. Excel snippet
  2. PowerPoint snippet

Context

My team is converting a COM/VSTO add-in to use the new Office JS APIs, and we need to make use of the custom properties of documents, since we already use them in our current COM/VSTO add-in.

Useful logs

This is the exception throw in Excel:

{ "stack": "RichApi.Error: A API que você está tentando usar não foi encontrada. Ela pode estar disponível em uma versão mais recente do Excel. Consulte a documentação: \"https://docs.microsoft.com/office/dev/add-ins/reference/requirement-sets/excel-api-requirement-sets\".\n at new n (https://appsforoffice.microsoft.com/lib/1/hosted/excel-win32-16.01.js:25:266633)\n at r.processRequestExecutorResponseMessage (https://appsforoffice.microsoft.com/lib/1/hosted/excel-win32-16.01.js:25:331795)\n at https://appsforoffice.microsoft.com/lib/1/hosted/excel-win32-16.01.js:25:329856", "message": "A API que você está tentando usar não foi encontrada. Ela pode estar disponível em uma versão mais recente do Excel. Consulte a documentação: \"https://docs.microsoft.com/office/dev/add-ins/reference/requirement-sets/excel-api-requirement-sets\".", "name": "RichApi.Error", "code": "ApiNotFound", "traceMessages": [], "innerError": null, "debugInfo": { "code": "ApiNotFound", "message": "A API que você está tentando usar não foi encontrada. Ela pode estar disponível em uma versão mais recente do Excel. Consulte a documentação: \"https://docs.microsoft.com/office/dev/add-ins/reference/requirement-sets/excel-api-requirement-sets\".", "errorLocation": "CustomPropertyCollection.getItemAt", "statement": "var itemAt = custom.getItemAt(...);", "surroundingStatements": [ "var workbook = context.workbook;", "var properties = workbook.properties;", "var custom = properties.custom;", "// >>>>>", "var itemAt = custom.getItemAt(...);", "// <<<<<", "itemAt.delete();" ], "fullStatements": [ "Please enable config.extendedErrorLogging to see full statements." ] }, "httpStatusCode": 400 }

And this is the exception thrown in PowerPoint:

{ "stack": "RichApi.Error: GeneralException\n at new n (https://appsforoffice.microsoft.com/lib/1/hosted/powerpoint-win32-16.01.js:26:251423)\n at r.processRequestExecutorResponseMessage (https://appsforoffice.microsoft.com/lib/1/hosted/powerpoint-win32-16.01.js:26:316755)\n at https://appsforoffice.microsoft.com/lib/1/hosted/powerpoint-win32-16.01.js:26:314815", "message": "GeneralException", "name": "RichApi.Error", "code": "GeneralException", "traceMessages": [], "innerError": null, "debugInfo": { "code": "GeneralException", "message": "GeneralException", "errorLocation": "CustomPropertyCollection.getItemAt", "statement": "var itemAt = customProperties.getItemAt(...);", "surroundingStatements": [ "var root = context.root;", "var properties = root.properties;", "var customProperties = properties.customProperties;", "// >>>>>", "var itemAt = customProperties.getItemAt(...);", "// <<<<<", "itemAt.delete();" ], "fullStatements": [ "Please enable config.extendedErrorLogging to see full statements." ] }, "httpStatusCode": 500 }

github-actions[bot] commented 1 month ago

Here are some similar issues that might help you. Please check if they can solve your problem.

Possible solution (Extracted from existing issue, might be incorrect; please verify carefully)

Hi i have noticed my system has some internal issue.i installed on another system and checked.now working fine

Reference:

Powered by issue-sentinel

guoms1 commented 1 month ago

Hi, @matheushoeltgebaum,

Thank you for bringing this issue to our attention.

I was able to reproduce the problem on both Excel and PowerPoint, across Desktop and Web versions. After thorough testing, I can confirm that this is indeed an API-related issue rather than a usage error.

I have reported the problem to the relevant team, and they are now aware of it (#9911046). We will keep you updated on any progress or potential workarounds.

Let me know if you have any further questions!

Best,