User should be able to fil the current month's timesheet only rest days should be readonly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2025 05:15 AM
As per requirement user should be able to fill the current month's days only rest days fields should be read only.
we have a field "weeks start on" there user has to select the first date of week.
If current date is 31/mar/2025 and weeks starts with 31 mar only , then user should be able to fill the field "monday" only rest all other days should be read only.
and if current date is 01/apri/2025 and field week starts on 31 mar, in this case user should be able to fill all the days except Monday as Monday is from previous month hence monday should be read only.
Please suggest how to achieve the same.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2025 05:54 AM
you can use onLoad client script and Display business rule on that table
Will week always start on Monday?
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
‎04-08-2025 06:12 AM
Can you please provide me the script which i am unable to make
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2025 06:59 AM
check script shared by @Kieran Anson
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2025 06:22 AM
Hi,
Yes this is possible with an onLoad Client Script. However, you have to deactivate both Data Policies on time_card as UI Policies/Data Policies run AFTER a client script, so undoes what the client script applies
function onLoad() {
//get the week field and turn into a date obj
var weekStartOn = g_form.getValue('week_starts_on');
var userDateFormat = g_user_date_format;
var dateTimeNumber = getDateFromFormat(weekStartOn, userDateFormat);
var weekStart = new Date(dateTimeNumber); //assuming this is always a Sunday...could add code to validate that
for (var i = 0; i < 7; i++) {
//get the next date
var nextDate = new Date(weekStart);
nextDate.setDate(weekStart.getDate() + i);
//check if we move into a new month
if (weekStart.getMonth() !== nextDate.getMonth()) {
//get the long name, which matches the field name
var targetField = nextDate.toLocaleDateString('en-US', {
weekday: 'long'
}).toLowerCase();
g_form.setMandatory(targetField, false);
g_form.setReadOnly(targetField, true);
} else {
g_form.setMandatory(targetField, true);
}
}
}