Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

Dynamic Date population in the Set Field Values in the Automated Test Framework (ATF)

vishalk
Mega Expert

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'
};

find_real_file.png

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. 

1 ACCEPTED SOLUTION

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

find_real_file.png

find_real_file.png

Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

7 REPLIES 7

Giles Lewis
Tera Guru

I think the javascript expression should NOT be in quotes.

Ankur Bawiskar
Tera Patron

Hi Vishal,

Let me know if that answered your question.

If so, please mark my response as ✅ correct & 👍 helpful so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Manish Anand
ServiceNow Employee

javascript: gs.daysAgo(-7) is not working for custom UI, i tried all the options, but no luck.

Is there any way that i can provide future date in the custom UI?