ServiceNow sys_ui_action client enabled, perform save and redirect

I’m trying to perform a save and revert on a sys_ui_action in Service Now

function proceedWithUpdateFromForm() {

    g_form.save();

    if (dlg != null) {
        dlg.destroy();
    }

    if (returnUrl != 'null') {
        window.location.href = window.location.protocol + '//' + window.location.host + '/' + returnURL;
    } else {
        window.location.href = window.location.protocol + '//' + window.location.host + '/' + tblName + '_list.do?sysparm_userpref_module=' + module + '&sysparm_query=' + listQuery + '&sysparm_cancelable=true';
    }
}

I can not use “current.update()” as I have enabled “Client” option and “current” is ServerSide.

Issue is that with above code, only redirect happens, save doesn’t happen. And if I remove returnURL part, then save happens, and redirect does not happen.

I want to save and then redirect.

Please advice.

I tried following things: In both of these cases, after save() is successfull, rest code doesn’t get executed.

function proceedWithUpdateFromForm_No() {
    // Save the form data
    g_form.save().then(function() {
        alert("Form saved successfully!");
    }).catch(function(error) {
        alert('Error saving form: ' + error);
    });
}

function proceedWithUpdateFromForm() {
    g_form.save({
        onComplete: function() {
            alert("Form saved successfully!");
        },
        onError: function(error) {
            alert('Error saving form: ' + error);
        }
    });
}