1
votes

I have a CustomFunctions javascript that does work perfectly with sync functions but as soon as i try using Async function i get: "

Unhandled exception at line 21, column 707859 in https://appsforoffice.microsoft.com/lib/beta/hosted/excel-win32-16.01.js 0x800a139e - Der opstod en JavaScript-kørselsfejl: unexpected message type

" This happens before any javascript code is called on my js file. the message type is 1002 so ofcourse the error will be thrown given the javascript at the indicated place in the excel-win-16.01.js: "

if(i[t].messageType===1001)u.push(i[t]);else throw OfficeExtension.Utility.createRuntimeError(st.generalException,"unexpected message type", "

the json description for the function is:

    {
      "name": "helloasync",
      "description": "simple test string return",
      "helpUrl": "https://www.konsolidator.com",
      "result": { 
        "type": "string",
        "dimensionality": "scalar"
      },
      "parameters": [],
      "options": {"sync": false}
    },
        {
      "name": "ADD42ASYNC",
      "description": "asynchronously wait 250ms, then add 42",
      "helpUrl": "http://dev.office.com",
      "result": {
        "type": "number",
        "dimensionality": "scalar"
      },
      "parameters": [
        {
          "name": "num",
          "description": "Number",
          "type": "number",
          "dimensionality": "scalar"
        }
      ],
      "options": {
        "sync": false
      }
    }

JS Code:

function helloasync() {
    return new OfficeExtension.Promise(function (setResult) {
        setTimeout(function () {
            setResult("hello");
        }, 1000);
    });
}

function ADD42ASYNC(num) {
    // waits 1 second before returning the result
    return new OfficeExtension.Promise(function (resolve,reject) {
        //resolve(num);
        //reject(num);
        setTimeout(function () {
            resolve(num + 42);
        }, 1000);
    });
}

all of my async customfunctions fail! sidebar async functions works as expected as well as synchronous functions.

1

1 Answers

0
votes

Could you try referencing the following version of Office.js instead?

http://unpkg.com/@microsoft/office-js@custom-functions-preview/dist/office.js

The CDN is currently a bit of out date, but the above should give you the latest and greatest.

UPDATE, to be clear (and I'm not sure if that's currently pointed-out in the docs or not, I'm following up on that): your HTML page should look like:

    <script src="https://unpkg.com/@microsoft/office-js@custom-functions-preview/dist/office.js" type="text/javascript"></script>
    <script src="customfunctions.js" type="text/javascript"></script>
    <script type="text/javascript">
        Office.Preview.startCustomFunctions();
    </script>

Where the middle script (the customfunctions.js is a reference to whatever JavaScript file you're creating to author these functions).