Validate past date and current date using client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2023 11:10 AM
Hi All,
I am validating the past and current dates using client scripts. Validation for the past date is working fine but if i take the todays date its not working properly. Let me know if any changes required in my code.
Apart from creating script include and on change client scripts and validating with UI Policies and BR is there other options to validate the current date . Please let me know what are the changes to be done in my code to get the expected result.
Note : I am new to service now and learning the scripting part
Code :
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2023 11:16 AM
Hi @Sagar Pagar
I can validate using UI policies and here the main reason is i am learning the script .Please let me know what are the changes has to be done to work the script which i have written
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2023 11:33 AM - edited 07-07-2023 11:35 AM
Hi @sushma9
If u_date_of_reservation is date type filed.
try this script:-
var td = new GlideDate();
var rd = g_form.getValue("u_date_of_reservation"));
if (td > rd) {
g_form.addErrorMessage(" You Have Selected the Past Date .Please Select the Future Date For Reservation !!!!")
g_form.clearValue("u_date_of_reservation");
// below part of code is not working //
} else if (td = rd) {
g_form.addInfoMessage(" You Have Selected Todays Date .Please Confirm to create the Reservtaion !!!!")
return confirm();
} else{
g_form.addInfoMessage('Reservation is created successfully !!!');
}
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.
Regards,
Ranjit Nimbalkar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2023 07:07 PM
Its not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2023 01:14 AM
var dateTimeStr = g_form.getValue('u_date_of_reservation');
var dateArr = dateTimeStr.split(' ');
var rd = dateArr[0];
)If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.
Regards,
Ranjit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2023 08:42 AM
Its a date Time field