Shown error: There is a JavaScript error in your browser console

Eduardo Mendez1
Kilo Contributor

Good afternoon, in a service added a script for the consultation of a field type reference, where deposit values in that field (email, phone) in a couple of variables (mail, ph).

This script works correctly in ServiceNow.Pero causes a problem with the service portal and does not perform the action.(Shown error: There is a JavaScript error in your browser console) which shows more detail the following error: [SCRIPT:EXEC] Error while running Client Script "Cs:SetPhone": TypeError: Cannot read property 'name' of undefined.

 

Anyone that can help me?

 

find_real_file.png

1 ACCEPTED SOLUTION

Hi,

Try below code,

function onChange(control, oldValue, newValue, isLoading) {

var caller = g_form.getReference('requested',doThis);

function doThis(caller){
if (isLoading) {
g_form.setValue('email',caller.email);
}
if (newValue != oldValue){
g_form.setValue('email',caller.email);
}
if (newValue == '') {
g_form.setValue('email','');
}
}
}

View solution in original post

4 REPLIES 4

Tim Deniston
Mega Sage
Mega Sage

The yellow error above that says you need to provide a callback. Are you using g_form.getReference()? If so, try providing it a callback, like g_form.getReference(doThis) and then define a function called doThis(grResponse), where grResponse is the GlideRecord(s) you're processing. 

Hi Tim,

 

Yes, My script!

 

function onChange(control, oldValue, newValue, isLoading) {
var caller = g_form.getReference('requested').name;
var Email = g_form.getReference('requested').email;
//g_form.addInfoMessage(Email);
//g_form.addInfoMessage(caller);

if (isLoading) {
g_form.setValue('email',Email);
}
if (newValue != oldValue){
g_form.setValue('email',Email);
}
if (newValue == '') {
g_form.setValue('email','');
}
}

 

So, 

I do not understand in which part to enter the grResponse.could you help me? or give me a clue?

Hi,

Try below code,

function onChange(control, oldValue, newValue, isLoading) {

var caller = g_form.getReference('requested',doThis);

function doThis(caller){
if (isLoading) {
g_form.setValue('email',caller.email);
}
if (newValue != oldValue){
g_form.setValue('email',caller.email);
}
if (newValue == '') {
g_form.setValue('email','');
}
}
}

Rohit70
Tera Contributor

Hi ,
I am trying to get the user job title based on the user name selected in multirow variable set. Trying below Script Include and client script.. When trying to access the variable set on Service Portal I am getting "There is a JavaScript error in your browser console" error..
Script Include Name : Username_change
var Username_change = Class.create();
Username_change.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
managername_value: function() {
var value = this.request.getParameter("sysparm_id");
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', value);
gr.query();
if (gr.next()) {
var obj = {
//'u_department': gr.getDisplayValue('department'),
//'u_location': gr.getDisplayValue('location'),
//'u_jid': gr.getValue('employee_number'),
//'u_cost_center': gr.getValue('cost_center'),
//'u_manager': gr.getDisplayValue('manager'),
"u_title": gr.getDisplayValue('title'),
// "v_desk_phone_number": gr.getValue("phone"),
};
return JSON.stringify(obj);
}
},
type: 'Username_change'
});

 

Catalog client script name  : GetJobtitleOnchange

function onChange(control, oldValue, newValue, isLoading) {
//    if (isLoading || newValue == '') {
//       return;
//    }
var ga = new GlideAjax('Username_change');
    ga.addParam('sysparm_name', 'managername_value');
    ga.addParam('sysparm_id', newValue);
    ga.getXML(getdata);
 
    function getdata(response) {
        var ans = response.responseXML.documentElement.getAttribute('answer');
        var aa = JSON.parse(ans);
 
        
        g_form.getDisplayValue()("title", aa.u_title);
 
 
    }
   //Type appropriate comment here, and begin script below
   
}
 
Could you please help me correct the above code.