- 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:09 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 12:14 AM
it was not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 12:17 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 12:15 AM - edited 01-29-2024 12:26 AM
@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
Regards,
Shyamkumar