Are durations in flow designer extremely frustrating, or is it just me?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2025 06:19 AM
Ok. So this is my usecase:
I want to have a functionality in a flow where I read the instance name.
- If it's a subprod instance, I want to set a duration of 30 seconds.
- If it's a production instance, I want to set a duration of 30 days.
This is so I can run actual full tests of flows in subprod instances, without having to manually change back and forth between subprod/prod durations, and incidentally commit short test durations in our production environment.
Yes, that has happened 😉
So, I thought I could just create a flow variable of type string, then set "d hh:mm:ss" on the Wait for condition action. Nope. That doesn't work. Well, I can assign the datapill, but it won't work.
I then tried creating a custom action where I pass two values: One subprod duration and one prod duration.
They're defined as duration type input variables.
I also define a duration type variable as an output variable.
So, when I test that custom action, I see that if I set a duration of 10 seconds, the value then becomes a string, and that string will be 1970-01-01 00:00:10. If I set a duration of 30 days, it becomes 1970-01-31 00:00:00.
And when I try to pass that to the duration type output variable, I'm told that it's the wrong type.
I've tried two different approaches, as shown below.
(function execute(inputs, outputs) {
// ... code ...
})(inputs, outputs);
// Define variables
var devInstance = "dev";
var testInstance = "test";
var sandboxInstance = "sandbox";
var prodInstance = "prod";
var instName = inputs.instanceName;
// Decide if instance is a SUBPROD instance
if (instName == devInstance || instName == testInstance || instName == sandboxInstance) {
outputs.duration_out = inputs.subprodDuration;
}
// Decide if instance is a PROD instance
else if (instName == prodInstance) {
outputs.duration_out = outputs.duration_out.add(new GlideDuration(new GlideDateTime(inputs.prodDuration.getValue()).getNumericValue()));
}
Why do the duration type formats differ?
Why does my duration type input variable change to a string?
What am I not getting here?
AND WHY IS THIS SO UNNECESSARILY FRUSTRATING!?!?!?!?!?!?!?!?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2025 01:23 AM
Hello @Jacob Saaby Nie
I am not sure if you tried with suggestion given by @Mark Manders
Here is something which is tried in my instance.
1) Two system properties as below one for prod & other for dev.
2) New Action without any input and output will give duration value on basis of our instance name.
3) Now over the flow using action we created and using wait for duration by passing output of action. Below is sample flow:
Now time for testing, I ran this flow and our flow is waiting for next 30 days (09 March 2025) from today (07 Feb 2025).
And this is it. Your flow will be now waiting amount of time that is stored in the system property. You can change it anytime without touching the Flow itself 😊
Servicenow counts the time of Duration since 1/1/1970 00:00:00 so if you want your Flow to be waiting, for example, for 10 days, simply set your sys property value to 1970-01-10 00:00:00.
Also, in your case flow variable didn't work as it wait for duration requires duration type. In your custom action instead of using Glideduration/GlideDatetime above process is way better and easier to understand rather than break much head. 😉
If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.
Thanks & Regards
Viraj Hudlikar.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2025 01:53 AM - edited 02-07-2025 02:53 AM
Thank you for your suggestion 🙂 I'll see if I can use that with Wait for Condition, somehow.
I'm not using "Wait for an amount of time" because that forces me to wait for that amount of time.
What I do in the flow is I wait for 2 specific things, using Wait for condition launched in parallel:
- I wait for the asset to change to a state which is not In Use
- I wait for the REQ/RITM to change to a closed state
- In both cases, I add a timeout for the amount of time I need to wait at that stage in the process
This way, I get both the timing aspect, but I can also react dynamically to either the request or the asset records changing.