- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
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
yesterday - last edited yesterday
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
yesterday
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday - last edited yesterday
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
yesterday
Thank you @Vishal Jaswal , its working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Thank you @namanajain , its working now
