- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2025 11:48 AM
Hi Team,
In var set I have Date time field , however i need to make it unpossible to choose date in future and show an info that date cannot be in future in 2 languages depending on what user session is.
I tried with Client script into car set and separately in item, also with UI policy, but still behavior is not changing. It had to be easy task, but I cant achieve the goal. Is it an issue that this variable is in var set?
Could you please help me to find an easy solution?
Thank you
Tina
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2025 01:06 AM
@FotinaG ,
CC : @GlideFather
It should work, if you write client script on variable set too.
Refer below screenshots.
Shashank Jain
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2025 01:50 AM
you can achieve this without scripting and simply use UI policy
Restrict user for selecting future dates in Service Catalogue.
Reference from above: You can write a simple UI Policy as show below:
Output will be as shown below:
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2025 12:12 PM - edited 08-13-2025 12:14 PM
@FotinaG ,
I have tried this on PDI and its working.
Please try this on change client script for that particular field.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var selectedDate = new Date(newValue);
var now = new Date();
// Normalize for comparison
selectedDate.setSeconds(0, 0);
now.setSeconds(0, 0);
if (selectedDate > now) {
// Get user's session language (defaults to English if not found)
var userLang = (typeof g_user_language !== 'undefined' && g_user_language)
? g_user_language
: 'en';
// Default message
var msg = "Date cannot be in the future.";
// Add translations
if (userLang.startsWith('fr')) {
msg = "La date ne peut pas être dans le futur.";
} else if (userLang.startsWith('de')) {
msg = "Das Datum darf nicht in der Zukunft liegen.";
}
// Add more languages if needed
// Show message in alert
alert(msg);
// Clear the invalid value
g_form.setValue(control.name, '');
}
}
If this helps, please consider marking my answer as helpful/accepted — it motivates me to stay active in the community and also helps others find relevant solutions more easily.
Thank you!
Shashank Jain
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2025 12:30 PM
Hello @Shashank_Jain ,
Thank you so much for your time, I tried it in my record producer, but it didnt work, should i create this client script in variable set where my Data/Time field is? Or this client script should be in Catalog item? Should I add my ral var name somewhere in code or just set Varible name in client script field after Type on Change?
Thank you so much again for your precisous time at such late evening.
Fotina
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2025 12:40 PM
@FotinaG ,
I guess you should give it a try on variable set client script and select the field on client script itself.
It should work.
Shashank Jain
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2025 12:47 PM
Hmm still failing, is it ok for esc?Because i try t use it on portal?
My apologies for all these questions