Error: onChange script error: TypeError: $ is not a function function

Not applicable

Hello All,

I am using London instance and want to highlight the 'Requester' field with the Red colour text and VIP flag on the Service Request(sc_request) table. Since this is an OOB functionality already available for the Incident table, i copied required client script and made the changes to accomodate the sc_request table. Below is my script:

function onChange(control, oldValue, newValue, isLoading) {
var callerLabel = $('label.sc_request.u_requester');
var callerField = $('sys_display.sc_request.u_requester');
if (!callerLabel || !callerField)
return;

if (!newValue) {
callerLabel.setStyle({backgroundImage: ""});
callerField.setStyle({color: ""});
return;
}
g_form.getReference('u_requester', vipCallerCallback);
}

function vipCallerCallback(caller) {
var callerLabel = $('label.sc_request.u_requester').down('label');
var callerField = $('sys_display.sc_request.u_requester');
if (!callerLabel || !callerField)
return;

//check for VIP status
if (caller.vip == 'true') {
var bgPosition = "95% 55%";
if (document.documentElement.getAttribute('data-doctype') == 'true')
bgPosition = "5% 45%";

callerLabel.setStyle({backgroundImage: "url(images/icons/vip.gif)", backgroundRepeat: "no-repeat", backgroundPosition: bgPosition, paddingLeft: '30px' });
callerField.setStyle({color: "red"});
} else {
callerLabel.setStyle({backgroundImage: ""});
callerField.setStyle({color: ""});
}
}

When i check the request, i received an error message "onChange script error: TypeError: $ is not a function function () { [native code] }". Please refer attached screenshot.

Could you please help me to solve it?

Thanks & regards,
Jainil Shah

1 ACCEPTED SOLUTION

Ashutosh Munot1
Kilo Patron

HI,

If you want to use this $ code then you have to do one change on that client script.


Can you check Isolate Script flag on client script. Whether it is true or false.


It should be false to allow your DOM manupilation to work.

Thanks,
Ashutosh Munot

View solution in original post

12 REPLIES 12

hvrdhn88
Giga Patron

have you added the properties to enable the DOM manipulation on London release? because by default on client script it has been disabled..

 

glide.script.block.client.globals

 

adding one thread here.

 

https://community.servicenow.com/community?id=community_question&sys_id=d3e10fa9db98dbc01dcaf3231f96...

Ashutosh Munot1
Kilo Patron

HI,

If you want to use this $ code then you have to do one change on that client script.


Can you check Isolate Script flag on client script. Whether it is true or false.


It should be false to allow your DOM manupilation to work.

Thanks,
Ashutosh Munot

Not applicable

Hello Ashutosh,

 

Could you please tell me how to check Isolate Script flag?

The strange part is, it worked well for the script on the Incident form. Is it because it's OOB?

Thanks & regards,

Jainil Shah

how do you check isolate Script flag? I did not find it on my catalog client script.