Cell value not been updated while editing

Do you want to: Report a bug / how-to question
Document Server version: 9.3.1.8
Additional information:
Hello,

The following code works well generally

	var sheet = Api.GetActiveSheet();
    var cell = sheet.GetActiveCell();
	
    cell.SetValue("test")
    console.debug(cell.GetValue());

However, if the user edits the cell (for example by pressing F2), the changes are not processed, and cell.GetValue() returns the value of the cell from before entering edit mode.

Is there a way to force the cell to exit edit mode so I can retrieve the current value and/or modify it?

best,

Hey @humbol, :wave:

Thanks for the clear code example — I see exactly what you’re running into.

The value you get with cell.GetValue() is pulled from the database, not from the current in-memory edit state. While the user is typing in a cell (edit mode active, F2 pressed), the changes are not yet committed to the DB — they only get saved after the user finishes editing and moves focus to another cell (Enter, Tab, click elsewhere). That’s why GetValue() returns the old value until then.

You’ll see “All changes saved” at the bottom only after the edit is committed.

In your scenario, the editor doesn’t even know the new value exists yet because it hasn’t been flushed to the backend.

Could you tell me a bit more about your exact use case?

  • What are you trying to achieve with GetValue() right after/during edit?
  • Do you need the value while the user is still typing, or only after they finish?
  • Are you building a plugin, macro, or using the JS API from an external integration?

Once I understand the goal, we can probably find solution (or confirm if it’s a limitation that needs a feature request).

Thanks — looking forward to your reply! :hugs:

Hi Nikolas,

Thank you for your support. I am currently working on two scenarios where I am encountering this issue.

In the first scenario, which is similar to the ONLYOFFICE playground (Playground | ONLYOFFICE), I have several actions located outside of the ONLYOFFICE frame that trigger specific macros. Frequently, after modifying a cell, users click these external buttons without exiting the cell. As a result, the macros do not do the expected changes.

The second issue is related, I guess. Some of my external functions trigger a save operation. I request the “forcesave” command service from the server side, but again, then current field are not saved if the user is didn’t exit that cell.

I hope it helps. Thanks again for your help.

Best,

Humberto

Hey @humbol, :wave:

Quick test: after typing in the cell, please move to another cell (press Enter or Tab) before running your macro/forcesave. This commits the edit.

Does it work then?

If you can share the relevant macro code, it would help me suggest a solution.

Hello Nikolas,

Moving to another cell, or simply pressing Tab/Enter, is the workaround I ask users to do before running the macros.

I tried, within my macro, to move to another cell and select it. Visually, it looks ok, but in the end it has no effect.

So, is there a way to programmatically stop editing the current cell, it may definetly helps :slight_smile:

best,

Hey @humbol, :wave:

Thanks for the update.

Currently, there is no direct API method to programmatically force the cell to exit edit mode.
The most reliable workaround is still to ask the user to press Enter or Tab (or click another cell) before running the macro.

However, you can try combining Api.Save() with a small delay to give the editor time to commit the change:

var sheet = Api.GetActiveSheet();
var cell = sheet.GetActiveCell();

Api.Save();

setTimeout(() => {
    console.log("Current value:", cell.GetValue());
    // your further logic here
}, 1000);

Please note:
There is a known bug in v9.3.1 where Api.Save() sometimes doesn’t work reliably (internal #80842). It is already fixed and will be included in the upcoming v9.4 release.

If this approach doesn’t work well for your use case, feel free to share more of your macro code — we can try to find a better solution together.

Thanks for your patience! :blush: