Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

OnChange in catalog Portal

String
Kilo Sage

Am using onchange catalog client script for portal and using  GlideAjax call.

 when I load the page and change the field am getting "ErrorThere is a JavaScript error in your browser console"

 

Please guide me best practices 

3 REPLIES 3

Faiz Ahmed Moha
Giga Expert

Please attach code here, so that we can suggest you appropriate solution.

 

Regards

Faiz

Hi @Faiz Ahmed Moha  Please check the snipped code below 

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

    if (isLoading || newValue == '') {

        return;

    }

    

    var emsg = new GlideAjax('Customer'); 

    emsg.addParam('sysparm_name', "ErrorMessages"); 

 emsg.getXMLWait();

    var answer = emsg.getAnswer();

    var errMsg = JSON.parse(answer);

   var gaAJAX = new GlideAjax('Utilities'); 

    gaAJAX.addParam('sysparm_name', "cal"); 

    gaAJAX.addParam('sysparm_asset', g_form.getValue(‘abc’)); 

  gaAJAX.getXML(test);

 

 function test(response) {

var answer = response.responseXML.documentElement.getAttribute("answer");

if (answer == 'error') { 

g_form.setValue(‘abc’, 'false');

            g_form.setValue(‘abc’, 'true'); //asset

  getMessage(errMsg.ahc, function(msg) {

                g_form.showFieldMsg('testfield', msg, 'error');

});

 } else {

g_form.setValue(‘ab’, 'false'); 

            g_form.setValue(‘xyz’, 'false');

getMessage(errMsg.failed, function(msg) {

                g_form.addErrorMessage(msg);

            });

}}

Hi @String, Could you please confirm if this client script working fine in Desktop/Platform view but not in portal ?

 

Regards

Faiz