Macros: SetTimeout() value problem

function copier(){
    let workSheet = Api.GetActiveSheet();
    let copy = workSheet.GetRange("L2").GetValue();
    workSheet.GetRange("M2").SetValue(copy);
}

function resolveAfter2Seconds() {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve('resolved');
    }, 2000);
  });
}

async function asyncCall() {
  let workSheet = Api.GetActiveSheet();
  console.log('calling');
  const result = await resolveAfter2Seconds();
  console.log(result);
  workSheet.GetRange("L2").SetValue(result);
  copier()

}

asyncCall()

The values after the timeout are inserted into the cells, but are invisible until you make any changes to the sheet.

How to fix, avoid this problem?

Hello @pahetka

Currently, the execution of asynchronous methods via script of the macros is hampered by the need to update the canvas, which is a very resource-intensive process. That’s why your macros updates the values but does not display them in cells after executing the macros.
Unfortunately, right now the only way to display the changes is by manually inserting any data to a any cell.

We are sorry for the inconvenience.

I have also encountered using asynchronous syntax, or can provide a method for refreshing

Hello @huzedong2022

Unfortunately, situation with asynchronous methods in macros hasn’t changed yet.
Also, there is no method for refreshing available.

Sorry for the inconvenience.

Hello again @huzedong2022 @pahetka

I have just found out that you can recalculate values with this method:
https://api.onlyoffice.com/plugin/macrosamples/recalculatevalues

For example, to display changed values in the macro of original poster you should add Api.asc_calculate(Asc.c_oAscCalculateType.All); like that:

function copier(){
    let workSheet = Api.GetActiveSheet();
    let copy = workSheet.GetRange("L2").GetValue();
    workSheet.GetRange("M2").SetValue(copy);
}

function resolveAfter2Seconds() {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve('resolved');
    }, 2000);
  });
}

async function asyncCall() {
  let workSheet = Api.GetActiveSheet();
  console.log('calling');
  const result = await resolveAfter2Seconds();
  console.log(result);
  workSheet.GetRange("L2").SetValue(result);
  copier()
  Api.asc_calculate(Asc.c_oAscCalculateType.All);
}

asyncCall()

Sorry for not pointing to this method earlier.