Compare 2 Dates in Catalog Client Script and Script Include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2023 11:53 AM
Hello,
I have a requirement that if the start date selected in a Catalog form is equal to the start date in a custom table, the request cannot be submitted, and alert should be pop-up.
What is the best approach? I have created a Script Include to query the value in the custom table and compare it with the one selected in the Catalog form, then I created a Catalog Client Script to see if they match.
I know there's something wrong with my scripts, if someone could help me would be great.
Script Include:
var TASK_return_date = Class.create();
TASK_return_date.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDateDetails: function() {
var start_date = this.getParameter('date');
//var gdt = new GlideDate(start_date);
var gr = new GlideRecord('u_ep_equipment_list');
gr.addquery('u_start_date', start_date);
gr.query();
if (gr.next()) {
var sd = "Start Date: " + gr.u_start_date;
}
return sd;
},
type: 'TASK_return_date'
});
Client Script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('TASK_return_date');
ga.addParam('sysparm_name', 'getDateDetails');
ga.addParam('sysparm_date', g_form.getValue('beginning_date'));
ga.getXML(showDetails);
function showDetails(response) {
var gt = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('description', gt);
alert("Start Date: " + gt);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2023 12:24 PM
Se if this does any better:
var TASK_return_date = Class.create();
TASK_return_date.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDateDetails: function() {
var start_date = this.getParameter('date');
//var gdt = new GlideDate(start_date);
var gr = new GlideRecord('u_ep_equipment_list');
gr.addquery('u_start_date', start_date);
gr.query();
if (gr.next()) {
// var sd = "Start Date: " + gr.u_start_date;
return gr.getValue('u_start_date');
}
// return sd;
},
type: 'TASK_return_date'
});
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('TASK_return_date');
ga.addParam('sysparm_name', 'getDateDetails');
ga.addParam('sysparm_date', g_form.getValue('beginning_date'));
ga.getXML(showDetails);
function showDetails(response) {
var gt = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('description', 'Start Date: ' + gt);
alert("Start Date: " + gt);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2023 01:58 PM
Hi @Ian Mildon I did the changes you added in both scripts, but nothing happens, I'm getting a JavaScript pop-message, any ideas? Just want to find the date selected by the user in the equipment custom table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2023 12:27 PM
Hi @Diorella Angulo ,
Could you please change below line of code in script include to mentioned one and try
var start_date = this.getParameter('date');
var start_date= this.getParameter('sysparm_date');
Kindly mark Helpful if it works.
Thanks,
Rahul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2023 01:57 PM
Hi @Rahul Kumar Ko1 I did that change but still getting an JavaScript error when a pick a date. I'm trying to find the data selected from the user in the custom equipment table, and if they are the same, the request cannot be submitted.