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  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

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

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

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 ..

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  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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