0
votes

I want to try execute this function for Office API for JavaScript:

public loadCustomProperties() {
    Excel.run(async (ctx) => {
        let custom = ctx.workbook.properties.custom;    
        custom.load();
        return ctx.sync();
    })
}

But I got an error ERROR Error: Uncaught (in promise): GeneralException: An internal error occurred... (nothing specific)

When I'm trying to load properties instead of properties.custom everything works fine.

Please help :)

EDIT:
This is the error I get:

ERROR Error: Uncaught (in promise): GeneralException: An internal error occurred while processing the request. RichApi.Error: An internal error occurred while processing the request. at new r (excel-web-16.00.js:21) at t.c.processRequestExecutorResponseMessage (excel-web-16.00.js:21) at excel-web-16.00.js:21 at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:388) at Object.onInvoke (core.js:3760) at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:387) at Zone.push../node_modules/zone.js/dist/zone.js.Zone.run (zone.js:138) at zone.js:872 at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421) at Object.onInvokeTask (core.js:3751) at new r (excel-web-16.00.js:21) at t.c.processRequestExecutorResponseMessage (excel-web-16.00.js:21) at excel-web-16.00.js:21 at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:388) at Object.onInvoke (core.js:3760) at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:387) at Zone.push../node_modules/zone.js/dist/zone.js.Zone.run (zone.js:138) at zone.js:872 at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421) at Object.onInvokeTask (core.js:3751) at resolvePromise (zone.js:814) at zone.js:724 at rejected (main.js:103) at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:388) at Object.onInvoke (core.js:3760) at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:387) at Zone.push../node_modules/zone.js/dist/zone.js.Zone.run (zone.js:138) at zone.js:872 at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421) at Object.onInvokeTask (core.js:3751)

EDIT 2:

I found this is a known bug: https://github.com/OfficeDev/office-js/issues/179

2
Why are you using an async function without await in the body? Whats the point? Your problem might go away if you remove the async keywordshanks
It doesn't change anything. The error is shown when executing ctx.sync() so at this moment it doesn't matter what I do with custom because after ctx.sync() it breaks.Marcin Szałek

2 Answers

1
votes

modified code with 3 changes.

  1. missing async on first line
  2. missing 'function'
  3. finally as shanks mentions, you are missing the await on the context.sync()

and I added a console.log just to verify that properties were loaded and they are.

async function loadCustomProperties() {
   await Excel.run(async (ctx) => {
        let custom = ctx.workbook.properties.custom;
        custom.load();
        await ctx.sync();
        console.log(custom);
    })
}
0
votes

I've came up with this workaround method to load items. It turns out that if you ensure that count is greater than 0, you can safely load customProperties.

async function loadCustomPropertiess() {
    await Excel.run(async (context) => {
        var customProperty = context.workbook.properties.custom;
        var customPropertyCount = customProperty.getCount();
        await context.sync();

        if (customPropertyCount.value > 0) {
            customProperty.load();
            await context.sync();
            customProperty.items.forEach(prop => console.log(prop));
        } else {
            console.log("No custom properties");
        }
    });
}