- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2023 12:40 PM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2023 12:13 PM
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');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2023 04:17 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2023 06:09 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2023 10:04 AM - edited 08-04-2023 10:44 AM
Sure. Here I am using the step config twice to get a start and end time for my change:
Here I am using the outputs of those steps when setting field values for my change request:
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();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2024 12:41 AM
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: