Calling CustomFunctions.associate after await causes first invocation to fail

Brice Lambson 0 Reputation points
2024-10-03T23:42:10.06+00:00

I'm seeing an issue where calling CustomFunctions.associate after an await is causing the first invocation of the custom function to fail with #VALUE! A value used in the formula is of the wrong data type. Subsequent invocations of the custom function work as expected. I'm using a shared runtime. Is this a supported scenario?

await new Promise(r => setTimeout(r, 2000));

CustomFunctions.associate("HELLO", () => "Hello, World!");

Office.onReady();

I realize that moving it before the await will fix it for this simple scenario; however, my actual implementation requires a component that needs to be initialized asynchronously.

Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,989 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Brice Lambson 0 Reputation points
    2024-10-04T14:54:53.1933333+00:00

    I'm able to work around the issue by calling associate before any await calls and waiting for the component to finish initializing inside the function body.

    const component1Promise = component.create();
    
    CustomFunctions.associate("HELLO", async () => {
        const component1 = await component1Promise;
    
        return component1.hello();
    });
    
    const component1 = await component1Promise;
    // ...
    
    Office.onReady();
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.