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

DYCM
Mega Sage

Please provide details of the issue you are facing. It would be helpful if you can provide your expected result and the actual result. The more details you provide the easier we can solve the issue.

it was not working

when there is no firewall  with model xyz in the location I selected in catalog. it need to throw error, but I am not sure why the script was not working 

shyamkumar VK
Kilo Patron

@Ak8977 ,

Seems your not storing the sysparm value of Location in Server side which comes from client side ,Corrected script Include and added below ,  Also check if you have records in the table with the queries you have put on in the script (Another tip while testing)

 

 

 

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

validateFirewall: function(yesno, location) {

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

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

});

 

 

 

Also try to print logs in the client side to check if it is return answer from Server side or not 

Regards,

Shyamkumar

 

Please mark this as helpful and accept as a solution if this resolves your Ask.
Regards,

Shyamkumar