ScriptInclude and client script was not working

Ak8977
Tera Expert

The follwing script include and client script are not working

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }
    // Type appropriate comment here, and begin script below
    var yesno = g_form.getValue("installation_pending");
    var location = g_form.getValue("location");
    var check = new GlideAjax('TeamsRoomSiteValidation');
    check.addParam('sysparm_name', 'validateFirewall');
    check.addParam('sysparm_yesno', yesno);
check.addParam('sysparm_location', location);
    check.getXML(analyzeResponse);
    function analyzeResponse(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        if (!answer) {
g_form.addErrorMessage('No Firewall detected in this location.');
            g_form.clearValue('location');
        }
    }
}
//script inlcude

var TeamsRoomSiteValidation = Class.create();
TeamsRoomSiteValidation.prototype = Object.extendsObject(AbstractAjaxProcessor, {

validateFirewall: function(yesno, location) {
if (yesno === "Yes") {
var gr = new GlideRecord('cmdb_ci_ip_firewall');
gr.addQuery('location', location);
gr.addQuery('model', 'STARTSWITH', 'XYZ');
gr.query();

if (!gr.next()) {
return false;
}
}
return true;
},
type: 'TeamsRoomSiteValidation',

});




1 ACCEPTED SOLUTION

AnveshKumar M
Tera Sage
Tera Sage

Hi @Ak8977 

It is with the data type that you return and also you are not capturing the parameters that you pass to the Client Callable Script Include. Update your scripts to the one below.

 

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }
    // Type appropriate comment here, and begin script below
    var yesno = g_form.getValue("installation_pending");
    var location = g_form.getValue("location");
    var check = new GlideAjax('TeamsRoomSiteValidation');
    check.addParam('sysparm_name', 'validateFirewall');
    check.addParam('sysparm_yesno', yesno);
    check.addParam('sysparm_location', location);
    check.getXML(analyzeResponse);
    function analyzeResponse(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        if (answer === 'false') {
            g_form.addErrorMessage('No Firewall detected in this location.');
            g_form.clearValue('location');
        }
    }
}

 

 

Script Include:

 

var TeamsRoomSiteValidation = Class.create();
TeamsRoomSiteValidation.prototype = Object.extendsObject(AbstractAjaxProcessor, {

   validateFirewall: function(yesno, location) {
      var yesno = this.getParameter('sysparm_yesno');
      var location = this.getParameter('sysparm_location');
      if (yesno === "Yes") {
         var gr = new GlideRecord('cmdb_ci_ip_firewall');
         gr.addQuery('location', location);
         gr.addQuery('model', 'STARTSWITH', 'XYZ');
         gr.query();

         if (!gr.next()) {
            return 'false';
         }
      }
      return 'true';
   },
   type: 'TeamsRoomSiteValidation',
});

 

 

Please mark my answer helpful and accept as a solution if it helped 👍✔️

 

Thanks,
Anvesh

View solution in original post

7 REPLIES 7

Vishal Birajdar
Giga Sage

Hello @Ak8977 

 

Try like below :

Script include 

var TeamsRoomSiteValidation = Class.create();
TeamsRoomSiteValidation.prototype = Object.extendsObject(AbstractAjaxProcessor, {

validateFirewall: function() {

var yesno = this.getParameter('sysparm_yesno');   // Updates
var location = this.getParameter('sysparm_location');  //updates
if (yesno === "Yes") {
var gr = new GlideRecord('cmdb_ci_ip_firewall');
gr.addQuery('location', location);
gr.addQuery('model', 'STARTSWITH', 'XYZ');
gr.query();

if (!gr.next()) {
return false;
}
}
return true;
},

 

 

Client script : 

    var yesno = g_form.getValue("installation_pending");
    var location = g_form.getValue("location");

    var check = new GlideAjax('TeamsRoomSiteValidation');
    check.addParam('sysparm_name', 'validateFirewall');
    check.addParam('sysparm_yesno', yesno);
    check.addParam('sysparm_location', location);
    
    check.getXMLAnswer(analyzeResponse);
    function analyzeResponse(answer) {
       
        if (!answer) {
            g_form.addErrorMessage('No Firewall detected in this location.');
            g_form.clearValue('location');
        } else {
   // to do
        }
    }

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

AnveshKumar M
Tera Sage
Tera Sage

Hi @Ak8977 

It is with the data type that you return and also you are not capturing the parameters that you pass to the Client Callable Script Include. Update your scripts to the one below.

 

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }
    // Type appropriate comment here, and begin script below
    var yesno = g_form.getValue("installation_pending");
    var location = g_form.getValue("location");
    var check = new GlideAjax('TeamsRoomSiteValidation');
    check.addParam('sysparm_name', 'validateFirewall');
    check.addParam('sysparm_yesno', yesno);
    check.addParam('sysparm_location', location);
    check.getXML(analyzeResponse);
    function analyzeResponse(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        if (answer === 'false') {
            g_form.addErrorMessage('No Firewall detected in this location.');
            g_form.clearValue('location');
        }
    }
}

 

 

Script Include:

 

var TeamsRoomSiteValidation = Class.create();
TeamsRoomSiteValidation.prototype = Object.extendsObject(AbstractAjaxProcessor, {

   validateFirewall: function(yesno, location) {
      var yesno = this.getParameter('sysparm_yesno');
      var location = this.getParameter('sysparm_location');
      if (yesno === "Yes") {
         var gr = new GlideRecord('cmdb_ci_ip_firewall');
         gr.addQuery('location', location);
         gr.addQuery('model', 'STARTSWITH', 'XYZ');
         gr.query();

         if (!gr.next()) {
            return 'false';
         }
      }
      return 'true';
   },
   type: 'TeamsRoomSiteValidation',
});

 

 

Please mark my answer helpful and accept as a solution if it helped 👍✔️

 

Thanks,
Anvesh

Hello @AnveshKumar M ,
thanks for the solution . 
But  

I replaced if(yesno==="Yes")  with if(yesno =="Yes") then it worked.