Scoped App: onChange script error: TypeError: $ is not a function function () { [native code] }

Rajini2
Mega Sage

I have some styles on Incident caller field when it is a VIP, and it works perfectly.

 

Now, I am trying to modify & use this script in my scoped application, it gives an error "onChange script error: TypeError: $ is not a function function () { [native code] }". 

Rajini2_0-1679354415695.png

 

This is my onChange script.

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

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

function vipCallerCallback(caller) {
	var callerLabel = $('label.x_cerr2_ism.caller_id').down('label');
	var callerField = $('sys_display.x_cerr2_ism.caller_id');
	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: ""});
	}
}

 

I have "Isolate script: false"

 

Is there anything to do for a scoped application? Did I miss anything?

 

1 ACCEPTED SOLUTION

Allen Andreas
Administrator
Administrator

Hi,

You'd need to create a system property within your scope for this. Please reference this thread for assistance: https://www.servicenow.com/community/developer-forum/isolate-script-false-and-dom-manipulation-not-w... 


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

1 REPLY 1

Allen Andreas
Administrator
Administrator

Hi,

You'd need to create a system property within your scope for this. Please reference this thread for assistance: https://www.servicenow.com/community/developer-forum/isolate-script-false-and-dom-manipulation-not-w... 


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!