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
07-13-2024 12:52 AM
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
07-13-2024 10:44 PM
Hi @mahi1225 ,
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;
This code retrieves today's date, formats it as YYYY-MM-DD, and then passes it into the calendar field. You can enter this code in the "Set Component Values" step of your custom UI action in ServiceNow.
If my reply helped with your issue please mark helpful 👍 and correct ✔️ if your issue is resolved.
By doing so you help other community members find resolved questions which may relate to an issue they're having
Thanks,
Astik Thombare
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2024 11:28 PM
Hi Astik,
Not working please help this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2024 12:49 AM
Hi @mahi1225
It is tried and tested.
Mark Helpful/Solution.
Regards
Shaqeel
***********************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful." This action benefits both the community and me.
***********************************************************************************************************************
Regards
Shaqeel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2024 01:32 AM
Hi Shaqeel,
Not working