The CreatorCon Call for Content is officially open! Get started here.

onCellEdit wait for callback to finish

Singularity
Tera Expert

Hi,

 

I have a use-case where there is a filtered list. On editing a certain field, I need to:

- Re-calculate and update values in the entire visible list

- Refresh the list (since just updating the values is not enough, the list will still show the old view unless refreshed)

 

I have implemented an onCellEdit script that looks something like this:

 

function onCellEdit(sysIDs, table, oldValues, newValue, callback) {


var saveAndClose = true;
callback(saveAndClose);

 

// my call to server to do the calculations and update the values, and wait for response
var ga = new GlideAjax('UpdateValues');
...
ga.getXMLWait();

 

// i refresh the list after my ajax logic finished so the list now can show the updated values
GlideList2.get(table).refresh();

}

 

However the issue is that my AJAX call, and the refresh line sometimes happen too quickly and the list refreshes, but the builtin "callback(saveAndClose)" line has not yet finished saving the value to DB... So something like:

 

- callback(saveAndClose) runs

- my logic runs

- refresh runs, BUT "callback(saveAndClose)" is still pending

 

What happens then, is that:

- All values show properly in the list, except the cell that I have edited (it still has the old value on-screen, but the new value in DB)

 

If I delay the refresh line by 1 second with settimeout it works, but I wanted a better solution... Could you please let me know how I can wait for "callback(saveAndClose)" to finish completely and then do the refresh, or where I should place it in my script so it works properly?

0 REPLIES 0