How to integrate update and exit in one button?

I created a custom javascript button that executes this code:
nm_atualiza(‘alterar’); /* SC update function */
window.close();

Works great, except when the update function returns errors (required field for example). In this situation the window is closed and you think the updated has been done succesfully. But… nothing is updated !!!

The execution of the above code should stop after the update function giving errors, and show the errors. Only when there are no errors the close() function should be executed.

Any suggestions?

Re: How to integrate update and exit in one button?

Does the update function return a value so you can setup a condition?

ex:
if (nm_atualiza(‘alterar’)) == 0) {
window.close();
} else {
Alert(‘did not update’);
}

Regards,
Scott.