From 4ef7cbd292ea2dc8db82e5f020e0bac68827d631 Mon Sep 17 00:00:00 2001 From: Soumyadeep Dutta <78016846+Soumyadeep10@users.noreply.github.com> Date: Tue, 7 Oct 2025 19:53:23 +0530 Subject: [PATCH 1/3] Create README.md --- .../Return Date Validation/README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Client-Side Components/Catalog Client Script/Return Date Validation/README.md diff --git a/Client-Side Components/Catalog Client Script/Return Date Validation/README.md b/Client-Side Components/Catalog Client Script/Return Date Validation/README.md new file mode 100644 index 0000000000..6ad55f063c --- /dev/null +++ b/Client-Side Components/Catalog Client Script/Return Date Validation/README.md @@ -0,0 +1,15 @@ +This piece of code runs in an OnChange catalog client script for the field 'u_return_date' and validates the return date(u_return_date) in a ServiceNow Catalog item form to ensure: + +1. A start date(u_start_date) is entered before setting a return date(u_return_date). +2. The return date is within 6 months after the start date. +3. Return date is not the start date or before that. + +Let’s say with an example: + + u_start_date = 2025-10-01 + You enter u_return_date = 2026-04-15 + + Steps: + a)Difference = 196 days → More than 180 days + b)Result: u_return_date is cleared and error shown: “Select Return Date within 6 months from Start Date” + From e1645e1cbcd7f588713702224e0920de2d7ae29d Mon Sep 17 00:00:00 2001 From: Soumyadeep Dutta <78016846+Soumyadeep10@users.noreply.github.com> Date: Tue, 7 Oct 2025 20:04:00 +0530 Subject: [PATCH 2/3] Create validateReturndate.js --- .../validateReturndate.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Client-Side Components/Catalog Client Script/Return Date Validation/validateReturndate.js diff --git a/Client-Side Components/Catalog Client Script/Return Date Validation/validateReturndate.js b/Client-Side Components/Catalog Client Script/Return Date Validation/validateReturndate.js new file mode 100644 index 0000000000..e9bcfa96fb --- /dev/null +++ b/Client-Side Components/Catalog Client Script/Return Date Validation/validateReturndate.js @@ -0,0 +1,23 @@ +function onChange(control, oldValue, newValue, isLoading) { + if (isLoading || newValue == '') { + return; + } + var u_start_date = g_form.getValue('u_start_date'); //start date validation to check to see whether filled or not + if (!u_start_date) { + g_form.clearValue('u_return_date'); + g_form.showFieldMsg('u_return_date', 'Please enter start date', 'error'); + } else { + var startTime = getDateFromFormat(u_start_date, g_user_date_format); //converting to js date object + var returnTime = getDateFromFormat(newValue, g_user_date_format); + var selectedStartDate = new Date(startTime); + var returnDate = new Date(returnTime); + var returnDateDifference = (returnDate - selectedStartDate) / 86400000; //converting the diff between the dates to days by dividing by 86400000 + if (returnDateDifference > 180) { + g_form.clearValue('u_return_date'); + g_form.showFieldMsg('u_return_date', 'Select Return Date within 6 months from Start Date', 'error'); + } else if (returnDateDifference < 1) { + g_form.clearValue('u_return_date'); + g_form.showFieldMsg('u_return_date', 'Select Return Date in future than Start Date', 'error'); + } + } +} From 610ac81e45f1983b76c75069b522fe50b859731f Mon Sep 17 00:00:00 2001 From: Soumyadeep Dutta <78016846+Soumyadeep10@users.noreply.github.com> Date: Tue, 7 Oct 2025 22:21:46 +0530 Subject: [PATCH 3/3] Update README.md Changes to the file: 1. Use case description given. 2. One more example related to another part of the use-case added --- .../Return Date Validation/README.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Client-Side Components/Catalog Client Script/Return Date Validation/README.md b/Client-Side Components/Catalog Client Script/Return Date Validation/README.md index 6ad55f063c..08b40e0c12 100644 --- a/Client-Side Components/Catalog Client Script/Return Date Validation/README.md +++ b/Client-Side Components/Catalog Client Script/Return Date Validation/README.md @@ -1,11 +1,12 @@ -This piece of code runs in an OnChange catalog client script for the field 'u_return_date' and validates the return date(u_return_date) in a ServiceNow Catalog item form to ensure: +This piece of code was written as a part of an usecase where the return date value validation was expected to be after start date as well as within 6 months from the start date. This code runs in an OnChange catalog client script for the field 'u_return_date' and validates the return date(u_return_date) in a ServiceNow Catalog item form to ensure: 1. A start date(u_start_date) is entered before setting a return date(u_return_date). 2. The return date is within 6 months after the start date. -3. Return date is not the start date or before that. +3. Return date must be after the start date, it can't be same as it or before it. Let’s say with an example: +a) u_start_date = 2025-10-01 You enter u_return_date = 2026-04-15 @@ -13,3 +14,10 @@ Let’s say with an example: a)Difference = 196 days → More than 180 days b)Result: u_return_date is cleared and error shown: “Select Return Date within 6 months from Start Date” +b) + u_start_date = 2025-10-02 + You enter u_return_date = 2025-10-01 + + Steps: + a)Difference = -1 day → Return date put as 1 day before start date + b)Result: u_return_date is cleared and error shown: “Select Return Date in future than Start Date”