Catalog Client Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi all,
I am trying to configure a Date variable on a Catalog Item form so users can only select a date that is at least two weeks out from the current date. Using a Catalog Client Script, I tried scripting this function, which gives me no errors but seems to not change anything on the form.
Can anyone take a look at my script and tell me what I might be doing wrong?
Example: highlighted dates should be grayed out and not selectable:
My Script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
19 hours ago
Hi @CesarV_,
I don't think there would be possible way to "disable" the other options.
Instead you can add a field or info message clarifying that the date must be within defined range (2 weeks from today) and if user select any date in that range then doesn't allow to submit.
It would be:
- 1a) onLoad catalog client script to show the field message ALWAYS (upon loading the form)
- 1b) onChange CCS to show if the particular field is displayed conditionally (e.g. user selects a category in another varibale, this date field becomes visible and was not visible when a form was loaded, otherwise 1a) is enough)
- 2) onSubmit CCS with return false; which makes the submission impossible
Just a small example, you need to process teh 14 days condition better, it is just to show you hwo to disabel submission
if (g_form.getValue('your_date)' > 14) {
return false;
} else {
return true;
}
/* If my response wasn’t a total disaster ↙️ ⭐ drop a Kudos or Accept as Solution ✅ ↘️ Cheers! */
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
18 hours ago
Hi @CesarV_,
You can solve this with an onChange Catalogue Client Script on your date variable. In the script, compare the selected date with today + 14 days. If the chosen date is less, show an error and clear the field. and make field value null ( make sure you mark date field is mandetory)
script -> here my date field name is 'my_date'. so replace it.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
// Today's date
var today = new Date();
today.setHours(0, 0, 0, 0);
// Minimum allowed date (14 days from today)
var minDate = new Date();
minDate.setDate(today.getDate() + 14);
minDate.setHours(0, 0, 0, 0);
// Selected date from user
var selectedDate = new Date(newValue);
if (selectedDate < minDate) {
// Show error message under the field
g_form.addErrorMessage("You cannot select a date less than 2 weeks from today");
g_form.setValue('my_date', '');
} else {
// Clear any previous error message when valid
// g_form.hideFieldMsg('my_date', true);
g_form.addInfoMessage("date is valid");
}
}
Output – this is my script
if i select the date less than 2 weeks from now (today's date is 27-09-2025)
Then it shows the error
you can use this script as on change or on submit .let me know if you need script . but on change clientr script would be best solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
17 hours ago
@CesarV_ I believe you dn't need client script in this case, did you try UI policy.
The condition should be <date variable> "Relative (operator) after 14 Days from now".
Once you select the variable and operator as "relative", you will get other options to select. This way you can achieve this without script login.
After the condition, in the run script under "execute if true" , you can throw and alert or clear the field if earlier dat is selected.
Please mark the answer correct/helpful accordingly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
16 hours ago
@RaghavSh you are right, this is excellent advice!
/* If my response wasn’t a total disaster ↙️ ⭐ drop a Kudos or Accept as Solution ✅ ↘️ Cheers! */