ATF - how to add dynamic date but specifying time

Latoya
Kilo Guru

Hi

I know these works with the date fields for ATF

javascript: gs.daysAgo(-1);       Tomorrow

javascript: gs.daysAgo(1);             Yesterday

javascript: gs.daysAgo(-31);         31 days in future

javascript: gs.daysAgo(31);            31 days in past

javascript: gs.nowDateTime();        today

 

However. how do I specify the time?

For the change request form. I have planned start and end date fields that need to be on the same day but different times

 

Even if maybe the end date could be X hours after start date would help.

I was told that with ATF the javascript needs to be on one line of code. 

Any tips would be appreciated.

 

Thank you in advance

 

 

1 ACCEPTED SOLUTION

Latoya
Kilo Guru

Add the following to the above format .split(' ')[0].concat(' ', 'HH:MM:SS');

For tomorrow at 1am time example: javascript: gs.daysAgo(-1).split(' ')[0].concat(' ', '01:00:00');

View solution in original post

5 REPLIES 5

Alex Rose
Tera Guru

Hi there,

 

I was actually writing a similar test for change_request today and my solution to this problem was to create a step configuration.  It takes three inputs: days, hours, and minutes, and adds them to the current time, and outputs the new dateTime object that can be used for later steps like creating your change request.

 

The code for the step config is:

(function executeStep(inputs, outputs, stepResult, timeout) {

	var dateTimeOffset = new GlideDateTime();
	dateTimeOffset.add(inputs.u_days * 24 * 60 * 60 * 1000);
	dateTimeOffset.add(inputs.u_hours * 60 * 60 * 1000);
	dateTimeOffset.add(inputs.u_minutes * 60 * 1000);

	
	outputs.u_datetimeoffset = dateTimeOffset;
	stepResult.setSuccess();

}(inputs, outputs, stepResult, timeout));

You just need to set up three integer inputs, and one dateTime output.  I actually didn't know about the inline javascript for this, and maybe my solution is overkill, but it worked for me.

Hi Alex, 

Thanks for the response

Can you paste the example of the ATF steps/input you used with this step config or a screenshot from inserting this to specifying values. I would appreciate it.

Sure.  Here I am using the step config twice to get a start and end time for my change:

AlexRose_0-1691168459679.png

 

Here I am using the outputs of those steps when setting field values for my change request:

AlexRose_1-1691168538976.png

 

Here's the description generator script for the step configuration:

 

function generateDescription() {
    // the global variable 'step' represents the current glide record
    var description = gs.getMessage("Returns a dateTime object relative to the current time: \n"
		+ "{0} Days \n", step.inputs.u_days);
	description += gs.getMessage("{0} Hours\n", step.inputs.u_hours);
	description += gs.getMessage("{0} Minutes\n", step.inputs.u_minutes);
	
	// your code here
	return description;
}
 generateDescription();

 

 

Hi Alex, 

 

I have tried to use your code/solution to my challange. I just need to add to add days, not hours or minuts. 

I have used the following code:

(function executeStep(inputs, outputs, stepResult, timeout) {
var newdate = new GlideDateTime();
newdate.add(inputs.u_days* 24 * 60 * 60 *1000);
outputs.u_date = newdate;
stepResult.setSuccess();
 
I have created an integer input and an calendar/date output.
But I can.t connect the test step 'set variablevalues (SP)' with the new test step, get variable Date.
Do you know what the problem might be?
NicoletaSambo_1-1713426099007.png

 

 
}(inputs, outputs, stepResult, timeout));