- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2024 11:32 PM
The follwing script include and client script are not working
//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',
});
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 12:25 AM - edited 01-29-2024 12:29 AM
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 👍✔️
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 12:19 AM
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
}
}
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 12:25 AM - edited 01-29-2024 12:29 AM
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 👍✔️
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 01:48 AM
Hello @AnveshKumar M ,
thanks for the solution .
But
I replaced if(yesno==="Yes") with if(yesno =="Yes") then it worked.