Date field not populating in UI Action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
14 hours ago
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 :
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
13 hours ago - last edited 13 hours ago
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
13 hours ago
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12 hours ago
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.
