Now Experience Catalog Item Set Focus to specific variable on Change, I can't get it to work

litchick10
Tera Guru

I am populating a list collector base on the value of another list collector.  This works great but the focus shifts to the second list collector and users might be confused, I'd like to refocus on the original list collector after populating the second field. 

 

I've tried the following that didn't refocus

g_form.getControl('field_name').focus();

g_form.getElement('field_name').focus();

g_form.getFormElement('field_name').focus();

g_form.getControl('field_name').scrollIntoView();

g_form.getElement('field_name').parentElement.lastElementChild.firstChild.focus();

 

Here's my current script without a focus:

Isolate Script = false (also tried with true)

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) {
        return;
    }
    g_form.hideFieldMsg('technology_cmdb_ci_business_app');
    if (newValue == '') {
        g_form.clearValue('technology_customer_facing');
        g_form.showFieldMsg('technology_cmdb_ci_business_app', 'You cannot select Customer Facing Business Applications with this field empty');
    } else {
        var cmdb = new GlideAjax('getTableDataUtils');
        cmdb.addParam('sysparm_name', 'getList');
        cmdb.addParam('sysparm_query_table', 'cmdb_ci_business_app');
        cmdb.addParam('sysparm_query_fields', 'sys_id');
        cmdb.addParam('sysparm_query_encodedQuery', 'sys_idIN' + newValue + '^u_customer_facing=Yes');
        cmdb.addParam('sysparm_query_order', 'sys_id');
        cmdb.getXML(getInfo);
    }
    function getInfo(response) {
        var custFace = [];
        var answer = response.responseXML.documentElement.getAttribute("answer");
        if (answer) {
            answer = answer.replace(/},{/g, '}},{{');
            var answerArr = answer.split('},{');
            for (var i = 0; i < answerArr.length; i++) {
                var answerObj = JSON.parse(answerArr[i]);
                custFace.push(answerObj.sys_id.toString());
            }
            g_form.clearValue('technology_customer_facing_business_app');
            if (g_form.getValue('technology_customer_facing') != 'Yes') {
                g_form.setValue('technology_customer_facing', 'Yes');
            }
            g_form.setValue('technology_customer_facing_business_app', custFace); //Here is where I need to refocus on technology_cmdb_ci_business_app
        } else {
            if (g_form.getValue('technology_customer_facing') != 'No') {
                g_form.setValue('technology_customer_facing', 'No');
            }
        }
    }
}

Any help is appreciated 

0 REPLIES 0