logo

NJP

g_form bring a form tab into focus

Import · Nov 24, 2019 · article

This is a nice little script that brings an out-of-sight field on an unfocused tab to the forefront when the user takes an action.

As an example, a user is working on a change task and hits Cancel Task.

image

But we want the user to enter closure information when cancelling the task, so we want the Closure Information tab to get the focus like this...

image

Here's the UI Action that controls this behavior

function moveToClosed() {
    if(g_form.getValue('close_notes')==''){
        g_tabs2Sections.setActive(1);//sets the second tab to active (the first tab is 0)
        g_form.setMandatory('close_notes',true);
        g_form.addErrorMessage("You must provide close notes to cancel this task");

    }else{
        g_form.setValue('state', 4);
        gsftSubmit(null, g_form.getFormElement(), "change_task_to_cancelled");
    }
}

if (typeof window == 'undefined')
   setRedirect();

function setRedirect() {
    current.update();
}

Have fun!

View original source

https://www.servicenow.com/community/now-platform-articles/g-form-bring-a-form-tab-into-focus/ta-p/2309514