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

Word API Field.updateResult() doesn't work when not executed from task pane add-in #4208

Closed
AlexPeek01 opened this issue Mar 4, 2024 · 3 comments
Assignees
Labels
Area: Word Issue related to Word add-ins Needs: author feedback Waiting for author (creator) of Issue to provide more info Status: no recent activity Issue or PR is stale (no recent activity)

Comments

@AlexPeek01
Copy link

Your Environment

  • Platform: Office on the web & PC desktop
  • Host : Word
  • Office version number: 2401 (Build 17231.20236)
  • Operating System: Windows 11 Pro
  • Browser (if using Office on the web): Chrome

Expected behavior

When calling updateResult() on a field it should update the field to the current custom property value. This should happen regardless from how the function is triggered.

Current behavior

Field.updateResult() gets executed but doesn't actually update the field values. It doesn't throw an error, but simply does nothing when triggered from an ExecuteFunction Action. When triggered from a Task Pane it works perfectly.

Steps to reproduce

  1. Create an add-in with both a task pane action and an executeFunction action.

  2. Create a Word document

  3. Add a field to the document (Insert > Quick Parts > Field > DocProperty > {pick any prop that you will be able to update easily, I use Title for testing} )
    image

  4. Execute the following code snippet from both actions. (The task pane can be an empty web app, since the updateResult works when simply pasting the code in the dev tools console).

async function updateAllFields(event) {
    await Word.run(async (context) => {
        // typically we would fetch the custom properties from the API and store them in the custom properties here, 
        // but for you to reproduce this simply rename the file since this will update the Title property that you added to your field.
        context.document.body.fields.load();
        await context.sync()

        var field = context.document.body.fields.getFirstOrNullObject();

        while (true) {
            context.document.body.fields.load();
            await context.sync()

            field.load(["code", "result", "type", "locked", "isNull"]);
            await context.sync();

            if (field.isNull) {
                break;
            }

            field.updateResult();
            field.select();
            context.sync();

            field = field.getNextOrNullObject();
        }
    });

    event.completed();
}

Context

We are building an add-in that gets properties from an API and stores these in the document.properties.customProperties. These custom properties are then inserted into a document as a docProperty field. We now have a Ribbon buttons that fetches the up-to-date properties from the API and sets them correctly in the custom properties. However when I iterate over the field collection and call the field.updateResult function, it simply skips over without error and continues.

This behaviour is only when using an Action with type ExecuteFunction. If I run the exact same code from a task pane add-in it does work as expected.

Useful logs

I'd love to provide errors or logs, but I'm not getting any. Everything appears to execute successfully, but the field doesn't update.

@microsoft-github-policy-service microsoft-github-policy-service bot added the Area: Word Issue related to Word add-ins label Mar 4, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs: attention 👋 Waiting on Microsoft to provide feedback label Mar 4, 2024
@yilin4
Copy link

yilin4 commented Mar 7, 2024

@AlexPeek01 #4050 This issue is similar with yours, you can take a look for reference.
The current supported field type of online Word and desktop Word is like following:
image

@zhenhuangMSFT zhenhuangMSFT added Needs: author feedback Waiting for author (creator) of Issue to provide more info and removed Needs: attention 👋 Waiting on Microsoft to provide feedback labels Mar 11, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the Status: no recent activity Issue or PR is stale (no recent activity) label Mar 15, 2024
Copy link
Contributor

This issue has been automatically marked as stale because it is marked as needing author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. Thank you for your interest in Office Add-ins!

Copy link
Contributor

This issue has been closed due to inactivity. Please comment if you still need assistance and we'll re-open the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Word Issue related to Word add-ins Needs: author feedback Waiting for author (creator) of Issue to provide more info Status: no recent activity Issue or PR is stale (no recent activity)
Projects
None yet
Development

No branches or pull requests

3 participants