Service Portal: Javascript error in your browser console

ramirch
Tera Contributor

Hello!

We have a catalog client script that uses $j. This works in the backend but in the Service Portal, it shows the error below.

 

ramirch_1-1678183815695.png

 

Is there an alternative of using $j in a catalog client script that works in both backend and Service Portal? The client script is:

 

    $j('#loc).change(function() {
		var locVal = $j('#loc').val();
		locVal = locVal .substring(0,locVal.indexOf(':'));
        g_form.setValue('location',locVal);
    });
    $j('#zipcode').change(function() {
		var zipcodeVal = $j('#zipcode').val();
		zipcodeVal = zipcodeVal.substring(0,zipcodeVal.indexOf(':'));
        g_form.setValue('zipcode',zipcodeVal);
    });
}

 

Thank you.

5 REPLIES 5

Hi @ramirch ,

 

Can you try with the below script 

var $j = jQuery.noConflict();
$j(document).ready(function() {
    $j('#loc').change(function() {
        var locVal = $j('#loc').val();
        locVal = locVal.substring(0, locVal.indexOf(':'));
        g_form.setValue('location', locVal);
    });
    $j('#zipcode').change(function() {
        var zipcodeVal = $j('#zipcode').val();
        zipcodeVal = zipcodeVal.substring(0, zipcodeVal.indexOf(':'));
        g_form.setValue('zipcode', zipcodeVal);
    });
});

 

The jQuery.noConflict() function is called to avoid conflicts with other libraries that may be using the "$" shorthand.

Regards,
Shravan
Please mark this as helpful and correct answer, if this helps you