- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2025 06:25 AM
Hi All,
I have a requirement to show a field based on the another field. Two fields are :
1. DLP Exception Granted of type (True/False)
2. Exception Granted date of type (date/time)
Now, the requirement is to show the field -"Exception Granted date" on the click of "DLP Exception Granted" and the second field should show the current date and time on the field.
The first part , i have achieved through UI Policy but unable to set the current date and time.
Can someone please help me out on setting the current date and time on the field -"Exception Granted date"?
Thanks,
Rooma
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2025 06:32 AM
don't use UI policy as it will require script.
Use onChange client script and set the current date/time using this
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if (newValue == '')
g_form.clearValue('dateTimeField');
if (newValue.toString() == 'true') {
var today_date = new Date();
var today_date_time_str = formatDate(today_date, g_user_date_time_format);
g_form.setValue('dateTimeField', today_date_time_str);
}
}
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
07-08-2025 06:38 AM - edited 07-08-2025 07:09 AM
Hi @roomawakar,
You can use an onChange client script, this will take date and time from browser:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue == 'true') {
var now = new Date();
var formatDate = now.getFullYear() + '-' +
String(now.getMonth() + 1).padStart(2, '0') + '-' +
String(now.getDate()).padStart(2, '0') + ' ' +
String(now.getHours()).padStart(2, '0') + ':' +
String(now.getMinutes()).padStart(2, '0') + ':' +
String(now.getSeconds()).padStart(2, '0');
g_form.setValue('u_exception_granted_date', formatDate);
} else {
g_form.setValue('u_exception_granted_date', '');
}
}
Regards,
Ehab Pilloor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2025 06:46 AM
@Ehab Pilloor @Community Alums
Nice coincidence, same script from both of you !
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2025 07:07 AM
It works.
There are same answers from different people in every other questions, so shouldn't be a surprise. I am not competing with you, you are there at the top. I get to learn from your answers. Just so happened that @Community Alums posted the solution too.
Regards,
Ehab Pilloor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2025 07:12 AM
No worries !
Keep learning and helping !
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader