- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2024 04:48 AM - edited 07-12-2024 04:52 AM
HI All,
There is a field on a catalog Item which should accept only future dates. It should not accept Past and the Current date.
Currently, the logic has been only written to throw an error if it accepts past dates. I need to update the logic so that it should throw an error when the user selects the current date as well.
Here is the snippet code for your reference.
var MyDayAjax = Class.create();
MyDayAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
// Checks - Date cannot be in the Past
checkNowDateTime: function() {
var firstDT = this.getParameter('sysparm_fdt');
var nowDT = gs.nowDateTime();
var diff = gs.dateDiff(firstDT, nowDT, false);
var datesplit = diff.split(' ');
gs.log('datesplit '+datesplit[0],'Rooma');
if (datesplit[0].indexOf(":") > -1 || datesplit[0] < 1) {
return true;
} else {
return false;
}
},
Can anyone please help here as I am not much sure about the dateDIff API?
Thanks,
Rooma
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2024 05:21 AM
You should use the newer subtract() method instead of dateDiff, but here's the documentation
You can also do this with a scripted UI Policy for a lower code approach
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2024 05:21 AM
You should use the newer subtract() method instead of dateDiff, but here's the documentation
You can also do this with a scripted UI Policy for a lower code approach
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2024 06:04 AM
Hi @Brad Bowman ,
I tried using scripted UI Policy but when I am adding the condition and saving it, the condition is clearing off but the logic is working.
Not sure why the condition is clearing off.