Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General Exception on context.sync after loading custom workbook properties with Excel Online only #179

Closed
1 task
petehallett opened this issue Jun 27, 2018 · 7 comments
Assignees

Comments

@petehallett
Copy link

I'm working on a project that requires access to the Custom Properties of a Workbook. i.e.

context.workbook.properties.custom;

I need to check to see if there are any Custom Properties in the workbook when I load the TaskPane.

My project works with Word Desktop, Word Online, Excel Desktop however produces an error in Excel Online.

I have created a sample project to demonstrate this problem. I need to test to see if there are any custom properties with a workbook.

I have a Custom properties Object, the Custom Properties are loaded then a general Exception error is thrown when context.sync is run.

Error: GeneralException: There was an internal error while processing the request.

Expected Behavior

When opening a Workbook with either, no custom properties, (i.e. a New Workbook) or an existing workbook with Custom properties, the expected

behaviour is that the Custom Properties are loaded into the object, as is demonstrated when using Word Desktop, Word Online or Excel Desktop.

Current Behavior

I can successfully load Custom Properties from Word Desktop, Word Online or Excel Desktop. This can be from a blank Document/Workbook or a Document/Workbook that currently has custom properties.

I currently receive the General Exception Error when using Excel Online, NOT Word Desktop, Word Online or Excel Desktop.

Steps to Reproduce, or Live Example

Below is a sample of my code from my sample TaskPane. The error will be reproduced when the TestCustomProperty() function is called.

(function () {
    "use strict";

    var cellToHighlight;
    var messageBanner;
    var applicationHostName;
    var sHostAPI = "Unsupported"; //Set the host application being used, e.g. Excel or Word

    // The initialize function must be run each time a new page is loaded.
    Office.initialize = function (reason) {
        $(document).ready(function () {
            // Initialize the FabricUI notification mechanism and hide it
            var element = document.querySelector('.ms-MessageBanner');
            messageBanner = new fabric.MessageBanner(element);
            messageBanner.hideBanner();

            if (Office.context.requirements.isSetSupported('WordApi', 1.3) === true) {
                sHostAPI = "WordAPI";
                applicationHostName = Word;
            }
            else if (Office.context.requirements.isSetSupported('ExcelApi', 1.6) === true) {
                sHostAPI = "ExcelAPI";
                applicationHostName = Excel;
            }

            //Check to see if the Host is Supported, return a message if it is not. 
            if (sHostAPI === "Unsupported") {
                app.showNotification("Add-in Not Available", "The App is not available for this Office Application.");
                $('#TaskPaneBody').prop('disabled', true);

            } else {

                $('#button-text').text("Test");
                $('#button-desc').text("Test Custom Properties");
                // Add a click event handler for the highlight button.
                $('#test-button').click(TestCustomProperty);
                                
            }

        });
    };

    function TestCustomProperty() {
        //Get the custom property and select it in the list on start up.
        applicationHostName.run(function (context) {
            var countOfCustomProperty;

            if (sHostAPI === "WordAPI") {
                var customProperty = context.document.properties.customProperties;
            }
            else if (sHostAPI === "ExcelAPI") {
                var customProperty = context.workbook.properties.custom;
            }

            customProperty.load();
            countOfCustomProperty = customProperty.getCount();

            return context.sync()
                .then(function () {
                    showNotification("Custom Property Count", countOfCustomProperty.value);
                });
         }) 
            .catch(errorHandler);

    }

    // Helper function for treating errors
    function errorHandler(error) {
        // Always be sure to catch any accumulated errors that bubble up from the Excel.run execution
        showNotification("Error", error);
        console.log("Error: " + error);
        if (error instanceof OfficeExtension.Error) {
            console.log("Debug info: " + JSON.stringify(error.debugInfo));
        }
    }

    // Helper function for displaying notifications
    function showNotification(header, content) {
        $("#notification-header").text(header);
        $("#notification-body").text(content);
        messageBanner.showBanner();
        messageBanner.toggleExpansion();
    }
})();

Context

We are trying to create a single Add-in that can be used across Word and Excel, both Online and Desktop version.

My add-in works sucessfully in Word Desktop, Online and Excel Desktop, however not Excel Online. Without being able to target Excel Online, we will be limiting the potential of our Add-in.

Your Environment

  • Platform [PC desktop, Mac, iOS, Office Online]: Office Online
  • Host [Excel, Word, PowerPoint, etc.]: Word and Excel
  • Office version number: Office 365 Build 1805, Office Online
  • Operating System: Windows 10
  • Browser (if using Office Online): IE Version 11 and Chrome 67.0.3396.87

Useful logs

  • Console errors
    Home.js:78 Error: GeneralException: There was an internal error while processing the request.
    Home.js:80 Debug info: {"code":"GeneralException","message":"There was an internal error while processing the request.","errorLocation":"","statement":"custom.load();","surroundingStatements":["var workbook=context.workbook;","var properties=workbook.properties;","var custom=properties.custom;","// >>>>>","custom.load();","// <<<<<","custom.getCount();"],"fullStatements":["Please enable config.extendedErrorLogging to see full statements."]}
@Rick-Kirkham
Copy link
Contributor

Rick-Kirkham commented Jun 27, 2018

@petehallett
The following very simple code works for me on both Excel and Excel Online. Please see if it works for you. If it does, you can try to discover what it is in your code that's causing a problem with Excel Online.

await Excel.run(async (context) => {
    var countOfCustomProperty;
    var customProperty = context.workbook.properties.custom;
    customProperty.load();
    countOfCustomProperty = customProperty.getCount();

    return context.sync()
        .then(function () {
            console.log("Custom Property Count", countOfCustomProperty.value);
        });
});

@tong-1324
Copy link

tong-1324 commented Jun 27, 2018

@Rick-Kirkham Thanks for following up on this.

@petehallett Thanks for letting us know the issue, and sorry about the problem. I could repro the issue on my side. It happens when you have an workbook with no custom properties and you try to call customProperties.load() in Excel Online. I have located the bug and I will have a fix on it very soon. I will let you know once the fix is checked-in. For now, here are a few workaround you could do.

Generally, we strongly recommend you never do an empty load on a proxy object. When you do an empty load call like proxyObject.load(), it will try to get you every property and call some hidden method under the proxy object, which is unnecessary in most scenarios.

If you want to call a method, you don't need to call any load. For example, in your scenarios, you could just call

    var customProperty = context.workbook.properties.custom;
    var customPropertyCount= customProperty.getCount();
    await context.sync();
    console.log(customPropertyCount);

If you want to get some properties under the proxy object, you could specify those properties in the "load" call instead of doing an empty load. For example, if you want to load the name and postion of a worksheet, you could do:

    var worksheet = context.workbook.worksheets.getItem("Sheet1");
    worksheet .load("name, position");
    await context.sync();
    console.log(worksheet.name);
    console.log(worksheet.position);

Avoiding empty "load" calls will have a huge improvement on the performance of your add-in. Also in this case, if you change your code to the first snippet above, you could avoid hitting the bug. Though we don't recommend you to do empty call, it should never throw an exception. Again, I apologize for the inconvenience and we will have the bug fixed very soon.

@JuaneloJuanelo
Copy link

Seems to be an issue with @petehallett 's code. awaiting for him to validate before closing.

@petehallett
Copy link
Author

petehallett commented Jul 1, 2018

@tong-1324
I can confirm that your recommended method of Not calling a load on the customProperties object will allow me to get a count on the Custom Properties of the workbook, i.e.

    var customProperty = context.workbook.properties.custom;
    customPropertyCount= customProperty.getCount();

            return context.sync()
                .then(function () {
                    showNotification("Custom Property Count", countOfCustomProperty.value);
                    //console.log(customProperty.items);
                });

However the other option of specifying the properties in the load call also produces the General Exception error. i.e.

    function TestCustomProperty() {
        applicationHostName.run(function (context) {

            if (sHostAPI === "WordAPI") {
                var customProperty = context.document.properties.customProperties;
            }
            else if (sHostAPI === "ExcelAPI") {
                var customProperty = context.workbook.properties.custom;
            }

            customProperty.load("items");

            return context.sync()
                .then(function () {
                    console.log(customProperty.items);
                });
         }) 
            .catch(errorHandler);
    }

This is once again only occurring within Excel Online. Not Desktop or Word Desktop or Word online.

I appreciate that you have found the bug and are looking for a resolution. Thank you again for your assistance.

@MarcinusX
Copy link

This is my workaround method to load items. 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");
        }
    });
}

@JuaneloJuanelo
Copy link

follow coding practice described on the issue.

@petehallett
Copy link
Author

Thanks to all contributors for your assistance with this issue.@tong-1324, will you be posting an update on this issue once the fix is checked in? Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants