How do I limit the date field so that future dates cannot be selected for Assessment Metrics?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
This is the survey form - assessment metrics - question data type: date that we want to limit.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hi @symonflores_23 ,
You can handle this using an onChange Client Script on the Assessment Instance Question table.
Create the Client Script
Go to Client Scripts and click New.
Configure the script as follows:
Table: as per your requirement
Type: onChange
Adding a condition is optional if you want to target a specific metric or question
Client Script example:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || !newValue) {
return;
}
var today = new GlideDate();
var selectedDate = new GlideDate(newValue);
if (selectedDate.after(today)) {
g_form.showFieldMsg(control, 'Future dates are not allowed.', 'error');
g_form.clearValue(control);
}
}
have a look at the code. It prevents users from selecting or submitting future dates and works for Assessment Metrics / Survey date questions.
If you find this useful, kindly mark it as Accept as Solution and Helpful.
Regards,
- Ankit
LinkedIn: https://www.linkedin.com/in/sharmaankith/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
normal client script or UI policy won't work on survey question
check this link
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
19m ago
You can't have a field validation on the assessment/survey question (date field is not supported) or Proactive approach(from client side) However you can do below (more reactive approach),
1.Write a BR on the assessment instance table when state changes and State changes to complete (you can also handle save scenario here)
2.Glide assessment instance question and check the string value (date entered)
3. check if its greater than today then abort the submission with a message
BR:
Change the Survey id here
2. Script logic
Result:
script:
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var asmtQuestion = new GlideRecord("asmt_assessment_instance_question");
asmtQuestion.addQuery("instance", current.sys_id);
asmtQuestion.addQuery("metric", "6c7d9a60c346f210c3dcd8477d013111"); //mettic = Question sys_id
asmtQuestion.query();
if (asmtQuestion.next()) {
var inputDate = asmtQuestion.getValue("string_value");
//--- Get today's date---
var today = new GlideDate();
today.setDisplayValue(gs.nowDate());
var gGivenDate = new GlideDate();
gGivenDate.setDisplayValue(inputDate);
inputDate = gGivenDate;
//---compare two dates-----
if (inputDate.after(today)) {
gs.addErrorMessage('The given date cannot be after today.');
current.setAbortAction(true);
}
}
})(current, previous);
Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025