- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2024 10:25 PM
Hi All,
We have ATF as attached(PFA:Wa_01) in that we have created the custom step Wait N Seconds as attached (PFA:Wait N Second_02) this step will stop the ATF till given seconds
In the Wait N Second step (PFA:Wa_03).
Here Our requirement is ,
when I give 120 seconds in Wait for N seconds step it is waiting for the response till 120 seconds. In some cases, the response is coming from the previous step that is Scheduled Script Execution is less than 120 seconds like for example 50 sec. in that situation I don't want to wait for 120 seconds it will run immediately once the response is received from the previous step (Scheduled Script Execution) and corresponding next step should be run.
Note: it should be work like timeout option in other steps.
Is this possible to do this requirement? If yes, please let me know what the changes are required.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2024 07:26 AM
Hi Khalid
Please try this. I tried to refactorize the code as per my understanding of the code shared by you.
(function executeStep(inputs, outputs, stepResult, timeout) {
var inputSeconds = 950; //Ankush: 950 seconds or 120 seconds
var milliseconds = parseInt(inputSeconds, 10) * 1000;
var start = new Date().getTime() + milliseconds;
var incidentFound = false;
do {
var gr = new GlideRecord('incident');
gr.addQuery('active', true);
gr.addQuery('state', '2');
gr.query();
if (gr.hasNext()) {
// Incident in "In Progress" state found
incidentFound = true;
break;
}
} while (new Date().getTime() < start);
stepResult.setOutputMessage('Found incident in progress: ' + incidentFound);
return incidentFound;
})(outputs, steps, params, stepResult, assertEqual);
--
Best Regards
Ankush
P.S. Please mark helpful/correct as appropriate to help the fellow community member in identifying the relevant answers.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2024 10:44 PM
adding the Wait N seconds step code below.
Description generation script :
Step execution script :

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 09:59 AM
Hi Khalid
I understand your requirement is for fluentWait (i.e. wait for a max of [timeout or an event occurs]). This is tricky to implement with a generic wait step.
The ideal way to solve this is in 2 steps:
1. Know which condition should be true (e.g.: a record is updated by a scheduled job)
2. Wait for that condition or max timeout, e.g.:
(function executeStep(inputs, outputs, stepResult, timeout) {
var seconds = parseInt(inputs.u_seconds2, 10) * 1000;
var start = parseInt(new Date().getTime()) + seconds;
while(start>parseInt(new Date().getTime())){
isConditionTrue(condition)
break;
}
stepResult.setOutputMessage('Waited ' + inputs.u_seconds + ' seconds.');
stepResult.setSuccess();
}(inputs, outputs, stepResult, timeout));
The tricky part here is to pass on the condition.
A simpler way would be to use 'Run server side-script' instead of the step 'Wait N seconds'. In that step, use the specific condition (e.g.: the record is updated) with the timeout. This implementation will be similar to the code snippet above, and you should be easily able to add your condition check.
--
Best Regards
Ankush
P.S. Please mark helpful/correct as appropriate to help the fellow community member in identifying the relevant answers.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 10:17 AM
Thanks for your quick response.
For Run server side-script ,could you please give me an example for an incident table with the conditions and timeout parameters.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2024 04:00 AM
Hi Ankush,
I have used the below script. but getting error as attached. could you please check the code.