GlideRecord in UI script

Rosy14
Kilo Sage

Hi,

I have below ui script where I want to replace the glideRecord by GlideAjax/g_scratchpad. ALso, want to know how to test if the code is working properly or not

redirectToUrl();

function redirectToUrl() {
grUserPreference = new GlideRecord('sys_user_preference');
grUserPreference.addQuery('user', top.window.NOW.user_id); // picking up current user as g_user doesnt work here.
grUserPreference.addQuery('name', 'sfRedirectPortal');
grUserPreference.query(response);

function response(result) {
        var url = '';
        var sflastRedirect = '';
        if (result.next()) {
            url = result.value;
            sflastRedirect = localStorage.getItem("sflastRedirect");

            if (url != "" && top.window.location.toString().indexOf(url) == -1 && (grUserPreference.sys_updated_on > sflastRedirect || sflastRedirect == null)) {
                localStorage.setItem("sflastRedirect", grUserPreference.sys_updated_on);
                top.window.location = url;
            }
        }
    }
}