ATF Custom Step Query

Khalid9030
Tera Contributor

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.

1 ACCEPTED SOLUTION

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.

View solution in original post

7 REPLIES 7

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.

@Ankush Agrawal 

 

Let me check this and let you know soon. 

@Ankush Agrawal  

Hope you're doing well

Our customer requirement is when we don't find the any records in that case I want to wait the query for 1 minute because that might be cause the performance issue for running the query every second.  For that I have added the else part in do loop is this good practice ? If not please let me know the best practice.

 

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;

        }

else{

  

   gs.sleep(60000)

 

}

    } while (new Date().getTime() < start);

 

    stepResult.setOutputMessage('Found incident in progress: ' + incidentFound);

    return incidentFound;