Save and exist UI action

eyal abu hamad
Mega Sage

Hey all, I created a new UI action that called save & exit. once I press it I want to save and redirect to previous page. now the problem is that my UI action must be in Client side. and the action name is : sysverb_update to overwrite the global Save & exit button.

function saveProject() {
    var fields = g_form.getEditableFields(); // get all editable fields
    for (var x = 0; x < fields.length; x++) { // for loop to each editable fields
        g_form.setMandatory(fields[x], false); //remove mandatory of the fields
        if (fields[x].substring(0, 5) == 'ni.VE') { //now I checked the variables on the catalog task
            var newDLName = fields[x].substring(5); //I removed the first 5 letters of the variable name. because here we got the ni.VE******* (ni.VI is the first 5 letters and the '*' is the sys id of the field)
            var gr = new GlideRecord('sc_item_option'); //i search the field in this table
            gr.addQuery('sys_id', newDLName);
            gr.query();
            if (gr.next()) {
                var mr = new GlideRecord('item_option_new'); //then I search the variable in this table
                mr.addQuery('sys_id', gr.item_option_new);
                mr.query();
                if (mr.next()) {
                    g_form.setMandatory(mr.name, false); //set the variable mandatory false
                }

            }
        }
    }


    gsftSubmit(null, g_form.getFormElement(), 'sysverb_update'); //save and stay
}

how can I redirect to previous page ? 

2 REPLIES 2

Mahesh23
Mega Sage

Hello,

You can use current.setRedirect(current).
In order to use both client and server script you can refer below article.

Execute both client & server code in one UI Action using gsftsubmit()

 

 

function saveProject() {
    var fields = g_form.getEditableFields(); // get all editable fields
    for (var x = 0; x < fields.length; x++) { // for loop to each editable fields
        g_form.setMandatory(fields[x], false); //remove mandatory of the fields
        if (fields[x].substring(0, 5) == 'ni.VE') { //now I checked the variables on the catalog task
            var newDLName = fields[x].substring(5); //I removed the first 5 letters of the variable name. because here we got the ni.VE******* (ni.VI is the first 5 letters and the '*' is the sys id of the field)
            var gr = new GlideRecord('sc_item_option'); //i search the field in this table
            gr.addQuery('sys_id', newDLName);
            gr.query();
            if (gr.next()) {
                var mr = new GlideRecord('item_option_new'); //then I search the variable in this table
                mr.addQuery('sys_id', gr.item_option_new);
                mr.query();
                if (mr.next()) {
                    g_form.setMandatory(mr.name, false); //set the variable mandatory false
                }

            }
        }
    }


    gsftSubmit(null, g_form.getFormElement(), 'sysverb_update'); //save and stay
}
//If this code is being run in the context of the SERVER...
if(typeof window == 'undefined')
runServerCode();
function runServerCode(){
//begin server code
current.setRedirect(current);
}

 

Maddysunil
Kilo Sage

@eyal abu hamad 

To redirect to previous page you can use:

<a onClick="window.location=history.back()">Back</a>

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

Thanks