- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2026 04:53 AM
Hi Everyone,
Why is my Date field (approval_date) not getting populated in a server-side UI Action in ServiceNow, even when using gs.nowDate() and setValue()? The state and other fields update correctly, but the Date field remains empty. What is the correct way to set a Date field in a UI Action?
Client - unchecked
Approval date field type - Date
Code :
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2026 06:16 AM - edited 04-29-2026 06:25 AM
Hello @suryakant30
Try below:
// Below will set YYYY-MM-DD
current.setValue('state', 'approved');
var today = new GlideDate();
current.setValue('approval_date', today.getValue());
current.setValue('approved_by', gs.getUserID());
current.update();
action.setRedirectURL(current);
// Below will set YYYY-MM-DD HH:MM:SS
current.setValue('state', 'approved');
current.setValue('approval_date', new GlideDateTime());
current.setValue('approved_by', gs.getUserID());
current.update();
action.setRedirectURL(current);
Hope that helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2026 06:33 AM
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2026 07:23 AM
Hi @suryakant30
1. gs.nowDate() and gs.nowDateTime() are not available in Scoped Applications
Ensure you are using GlideDateTime class instead
2. If you are not using scoped app , then it could be the case
Your approval_date is Date/Time field where you are trying to store gs.nowDate() which returns a date string
Ensure , in that case - you are using gs.nowDateTime() for Date/Time fields.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2026 06:16 AM - edited 04-29-2026 06:25 AM
Hello @suryakant30
Try below:
// Below will set YYYY-MM-DD
current.setValue('state', 'approved');
var today = new GlideDate();
current.setValue('approval_date', today.getValue());
current.setValue('approved_by', gs.getUserID());
current.update();
action.setRedirectURL(current);
// Below will set YYYY-MM-DD HH:MM:SS
current.setValue('state', 'approved');
current.setValue('approval_date', new GlideDateTime());
current.setValue('approved_by', gs.getUserID());
current.update();
action.setRedirectURL(current);
Hope that helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2026 11:29 PM
Thank you @Vishal Jaswal , its working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2026 06:33 AM
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2026 11:28 PM
Thank you @namanajain , its working now