
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2023 11:06 PM
Hello!
I have a requirement to add a random time in a wait for duration.
Initially, it was a wait for condition that had the following script:
var minutes = Math.floor(Math.random() * 45);
var duration = '00:' + minutes + ':00';
return new GlideDuration(duration);
But it wasn't the best practice, so I have to change the logic.
Initially I created a flow variable with the logic above and then I wanted to use it in a wait for duration, but the problem is that wait for duration doesn't support flow variables.
Then, I created a flow action that calls the flow variables (with the script) and the output should be the duration that the flow need to wait, but somehow it doesn't work.
This is the logic that I have:
1. Flow variable with the script: var minutes = Math.floor(Math.random() * 45);
I logged minutes and it shows correctly.
2. Created a duration of time that calls flow action from #3.
3. Flow action:
Input:
Script:
But my log already has minutes as undefined:
I guess I am doing something wrong, but at the moment I am stuck.
If you have any ideas or other solution, let me know.
Thank you,
Elena
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2023 11:36 PM
Managed to do it. This is how:
- Deleted the flow variable.
- All the logic is in the action
- Action output is type duration
- Back in flow, used the output from action in wait for duration

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2023 11:36 PM
Managed to do it. This is how:
- Deleted the flow variable.
- All the logic is in the action
- Action output is type duration
- Back in flow, used the output from action in wait for duration
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2023 06:24 AM
Very nice solution!
I had been looking to do something similar, but I wanted the timeframe to be a little more flexible, so that other internal developers would be able to use it too.
So, the script code in my action called Create Duration Object from Integer Value is as follows:
(function execute(inputs, outputs) {
var timer_wait_value = inputs.timer_wait_value;
var duration_set = 60000 * timer_wait_value;
var dur = new GlideDuration(duration_set);
outputs.duration = dur;
})(inputs, outputs);
So I accept the input in minutes, and convert it to a duration and then return the duration to be used in the subflow.
Makes for a nice easy solution, I just wish they had included it out of the box!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2024 12:34 PM - edited 04-22-2024 08:34 AM
Awesome folks! Thanks so much for sharing.
I used a version of Elena's that takes minutes and seconds and accepts nulls.. the problem, without input validation, you have to assume users will be kind enough to not insert more than 60 seconds or 60 minutes. Using Jeffery's, just leaving it in seconds rather than minutes.
var inputs = {
minutes:null,
seconds:0
};
var minutes = inputs.minutes ? inputs.minutes : 0;
//Math.floor(Math.random() * 5);
gs.print(minutes)
var seconds = inputs.seconds ? inputs.seconds : 0;
//Math.floor(Math.random() * 5);
gs.print(seconds)
var duration = '00' + ':' + minutes + ':' + seconds;
var dur = new GlideDuration(duration)
// var timer_wait_value = inputs.timer_wait_value;
// var duration_set = 60000 * timer_wait_value;
// var dur = new GlideDuration(duration_set);
gs.info('minutes {0} seconds {1} output', minutes,seconds + ' - ' + dur)