1

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.

Marc LaFleur
  • 31,987
  • 4
  • 37
  • 63
Nicky
  • 70
  • 5

1 Answers1

0

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).

  • well that at least changed something. Now i get the #GETTING_DATA and then nothing else happens. this happens on both of the methods in the original snippet. – Nicky May 14 '18 at 15:08
  • should i open a new question regarding the problem with Jquery ajax. it works fine from the side panel but i have no idea how to get i to work in the custom functions. – Nicky May 16 '18 at 12:11
  • My problem was because i had a reference to JQuery 3.3.1 before the office.js reference moving this to after the office.js reference solved the problem. Though this means that Jquery is still not working it gives and access denied when trying to call an jquery ajax method. – Nicky May 17 '18 at 11:04
  • The order of jQuery vs. Office.js shouldn't have mattered -- and the two can absolutely be used in conjunction with each other. Do you want to file an issue with repro steps/project on https://github.com/OfficeDev/office-js/issues/, so that the team can investigate further? – Michael Zlatkovsky - Microsoft May 20 '18 at 19:49
  • Not at the moment Michael, i currently am not able to reproduce the problem. so making reliable repro steps would be impossible for me. – Nicky May 24 '18 at 11:32