How to pass today's date in "Set Component Values (Custom UI)" step?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2024 08:11 PM
We have a calendar field through which we have to pass tomorrow's date. This calendar field can only be accessed using Custom UI. So, we chose the step "Set Component Values (Custom UI)" to pass the date into the calendar field. The code that we used was
javascript:gs.daysAgo(-1);
Image of ATF Test Script:
But, when executing, we noticed that, instead of the date, the whole text of the function "javascript:gs.daysAgo(-1);" is being displayed in the calendar field. Is there any other way to pass tomorrow's date or current date into the field?
Image when executing:
Note: This javascript function is working fine when we used for normal "Set Field Values" step, but not working for "Set Component Values (Custom UI)" step
#atf
#automatedtestframework
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2024 11:11 PM - edited 02-09-2024 11:13 PM
Hi Anjali,
To pass today's date in ServiceNow using a Custom UI step "Set Component Values", you can use the JavaScript code below:
var now = new Date();
var todayDate = now.getFullYear() + '-' + (now.getMonth() + 1) + '-' + now.getDate();
todayDate;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2024 11:11 PM - edited 02-12-2024 01:12 AM
above code taken as it is "Set Component Values" step for Date code as it is populated in field value not getting date value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2024 12:09 AM
Hi @Community Alums
If my answer helped you, please mark it helpful and correct.
Regards,
Amit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2024 12:45 AM
Hi Amit Did you get answer