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

Sai Shravan
Mega Sage

Hi @ramirch ,

you can use the jQuery keyword instead of $j in your client script to make it work in both backend and Service Portal.

Here's an updated version of your client script that uses jQuery instead of $j:

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

 

Regards,
Shravan

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

ramirch
Tera Contributor

@Sai Shravan Unfortunately this did now work. I'm still getting the Javascript error. 😞

Hi @ramirch,

 

Can you Inspect (Just right-click on any website's area and choose Inspect. You can also use your keyboard shortcut - Ctrl+Shift+I) on the browser, navigate to console and check which line is throwing the error.

Regards,

Shravan

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

@Sai Shravan This is the error when I used Inspect: TypeError: jQuery is not a function