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

ramd
Kilo Contributor

Hi There, 

We are currently building some reusable test cases using ATF (Automated Test Framework) Application. We have several test scenarios related to change management where the "Planned Start Date" and "End Date" should be dynamically populated to future date, typically the date and time should be anything between 3rd Sunday 09:00 pm PST - 12:00 AM PST. 

Is there any javascript available to meet this requirement? I want to populate the 3rd Sunday 09:00 pm PST, in the highlighted area as shown in the attached screenshot.

Please help. 

Thanks,

RD

 

find_real_file.png

1 ACCEPTED SOLUTION

Here's one way.

var myDatePicker = Class.create();
myDatePicker.prototype = {
    initialize: function() {
    },

	// Pass in year and month as numbers
	3rdSunday : function(year, month) {
		var first = 15; // the soonest that the 3rd Sunday can be
		var last = 21; // the latest that the 3rd Sunday can be
		
		var gdt = new GlideDateTime();
		gdt.setYearLocalTime(year);
		gdt.setMonthLocalTime(month);

		for (var day = first; day < last; day++) { 
			gdt.setDayOfMonthLocalTime(day);
			if (gdt.getDayOfWeekLocalTime() == 7) {
				return day;
			}
		}
		
		return;
	},

    type: 'myDatePicker'
};

Usage is:

var dom = new myDatePicker().thirdSunday(2018, 6);
// dom = 17, the date of the third Sunday in June 2018

If you want it to return the entire date (ex. 2018-06-17), simply change the return value in the function to 

return gdt.getDate();

View solution in original post

12 REPLIES 12

Chuck Tomasi
Tera Patron

One method would be to write your own script include that has a function to return the date/time of the third Sunday. Then call that script include from your field values similar to what you have above.

ex: javascript:new myDatePicker().3rdSunday();

The function would return the date/time you specific in your script. 

ex: 2018-06-17 21:00:00

Hi Chuck

Thank you so much for quick response. I am not that great in writing script include, could you please help me with required code. 

Thanks,

RD

Here's one way.

var myDatePicker = Class.create();
myDatePicker.prototype = {
    initialize: function() {
    },

	// Pass in year and month as numbers
	3rdSunday : function(year, month) {
		var first = 15; // the soonest that the 3rd Sunday can be
		var last = 21; // the latest that the 3rd Sunday can be
		
		var gdt = new GlideDateTime();
		gdt.setYearLocalTime(year);
		gdt.setMonthLocalTime(month);

		for (var day = first; day < last; day++) { 
			gdt.setDayOfMonthLocalTime(day);
			if (gdt.getDayOfWeekLocalTime() == 7) {
				return day;
			}
		}
		
		return;
	},

    type: 'myDatePicker'
};

Usage is:

var dom = new myDatePicker().thirdSunday(2018, 6);
// dom = 17, the date of the third Sunday in June 2018

If you want it to return the entire date (ex. 2018-06-17), simply change the return value in the function to 

return gdt.getDate();

javascript:new myDatePicker().3rdSunday(); 

... this didn't work when I tried setting a field value a custom service portal widget UI. I'm on a New York instance. My script include tests okay when I try the function on background script execution.