- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2020 07:58 AM
Greetings. I am trying to do something similar. I have a catalog item that I want to populate the "required by" date field with a date always a week from today. I added a script include:
var myDatePicker = Class.create();
myDatePicker.prototype = {
initialize: function() {
},
// pass in the number of days in the future
// usage: javascript:new myDatePicker().getFutureDate(3);
// the above will set your date to 3 days in the future
getFutureDate : function(futureDate) {
var gdt = new GlideDateTime();
gdt = gdt.addDaysLocalTime(futureDate);
return gdt.getDate();
},
type: 'myDatePicker'
};
But it doesn't seem to be setting the date. When I set a validation step looking for 11/22 it's failing. Any help would be appreciated.
Solved! Go to Solution.
- Labels:
-
Automated Test Framework
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2020 08:12 AM
Hi Vishal,
the below worked for me
javascript: gs.daysAgo(-7)
screenshot below; when I run it sets date to 7 days in future i.e. 11th May
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2020 10:30 AM
Hi,
So you want to set future date and that too 7 days from today; you can use this and it will work
javascript: gs.daysAgo(-7)
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2020 08:00 AM
when run this in script background it will run but when you put this in ATF then in wont give any result ...
I tried wrting script include and calling that in ATF , but no luck , with quotes or without quotes it wont work ..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2020 08:12 AM
Hi Vishal,
the below worked for me
javascript: gs.daysAgo(-7)
screenshot below; when I run it sets date to 7 days in future i.e. 11th May
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2021 02:38 AM
Hi
This works for me but where is this Javascript code already saved or where we can write to make it appear in ATF ?
I am new to Servicenow kindly share thanks
Regards
Ravinder