Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

UI Page processing script error - com.glide.script.RhinoEcmaError: "task" is not defined.

mike_allgire
Giga Guru

I don't create new UI Pages that often, and for most...it is a similar use-case, so copying the client script and processing script is warranted. I have a new UI Page created from a different UI Page; however, the processing script on submission for the new UI Page is giving an Evaluator error of com.glide.script.RhinoEcmaError: "task" is not defined. Anyone know a good reason why, as this method is also utilized in OOB UI Pages.

 

Here is the piece of the HTML. I have verified that the sc_task value is available in this HTML when passed from the UI Action.

<input type="hidden" id="cancelled" name="cancelled" value="false"/>
<input type="hidden" id="sc_task" name="sc_task" value="${sysparm_sys_id}"/>
<input type="hidden" id="sc_req_item" name="sc_req_item" value="${sysparm_ritm}"/>
<input type="hidden" id="sys_user" name="sys_user" value="${sysparm_sys_user}"/>
<input type="hidden" id="assignment_group" name="assignment_group" value="${sysparm_assignment_group}"/>
<input type="hidden" id="assignee" name="assignee" value="${sysparm_assignee}"/>

 

Here is the Client script snippets that adds the "task" value.

function cancel() {
    var c = gel('cancelled');
    c.value = "true";
    GlideDialogWindow.get().destroy();
}

function actionOK() {
    var task = gel('sc_task').value;
    var ritm = gel('sc_req_item').value;
    var stockroom = gel('stockroom').value;
    var accessories = [];
	
	//Check for value in the monitor field
    var monitor = gel('monitor').value;
    if (monitor && monitor != '') {
        accessories.push(monitor.toString());
    }

	//Check for value in the keyboard field
    var keyboard = gel('keyboard').value;
    if (keyboard && keyboard != '') {
        accessories.push(keyboard.toString());
    }

	//Check for value in the mouse field
    var mouse = gel('mouse').value;
    if (mouse && mouse != '') {
        accessories.push(mouse.toString());
    }

	//Check for value in the dock field
    var dock = gel('dock').value;
    if (dock && dock != '') {
        accessories.push(dock.toString());
    }

	
    if (accessories == '') {
        alert(getMessage("Please enter equipment to restock"));
        return false;
    } else {
        var form = document.forms['form.' + '${sys_id}'];
        addInput(form, "HIDDEN", "ritm", ritm);
        addInput(form, "HIDDEN", "stockroom", stockroom);
        addInput(form, "HIDDEN", "accessories", accessories);
        addInput(form, "HIDDEN", "task", task);
        return true;
    }
}

 

Here is the processing script...

if (cancelled == 'false' && accessories != '') {
    var q = new infoQueryHelper();

	//Return to catalog task
    var url = '/sc_task.do?sys_id=' + task;  // <--THIS IS TRIGGERING THE EVAL ERROR
    var equip = [];
    var accessories = accessories.split(',');

    for (var i = 0; i < accessories.length; i++) {
        var alm = new GlideRecord('alm_consumable');
        if (alm.get(accessories[i])) {
            alm.install_status = 6;
            alm.substatus = 'available';
            alm.request_line = ritm;
            alm.stockroom = stockroom;
            alm.location = '';
            equip.push(alm.getDisplayValue());
            alm.update();
        }
    }
    if (equip != '') {
        gs.addInfoMessage(equip + ' restocked to the ' + q.getRecObj('alm_stockroom', 'sys_id=' + stockroom).name);
        var ritm2 = new GlideRecord('sc_req_item');
        if (ritm2.get(ritm)) {
            ritm2.work_notes = msg;
            ritm2.update();
        }
    }
    response.sendRedirect(url);
}
1 REPLY 1

Prana Krushna
Giga Guru

@mike_allgire This post link might help you to resolve this.
https://www.servicenow.com/community/developer-forum/in-ui-page-how-to-send-a-variable-value-from-cl...
Mark this as helpful if it works for you.