How to script in 'Wait for Condition' action in Flow Designer

Preethi Tiruma1
Tera Contributor

I have a requirement where I am working on Order Guide, I have to keep the remaining ritms to wait, until one of the RITM's first 2 tasks are closed complete. I used the below scripting for that within Wait for Condition action. But its not working, action is executing before meeting the conditions. Am I doing anything Wrong here?

 

Below is the code used:

 

var ritmSysId = fd_data.flow_var.ritm_sysid; // Adjust this based on your actual Flow variable name
//var ritmSysId = 'a25627919353c2101de0fa718bba1002';

var grRitm = new GlideRecord('sc_req_item');
if (grRitm.get(ritmSysId)) {
    var requestSysId = grRitm.request;
    var catItemSysId = "17f453f7835a8210b57211d6feaad3e9"; // Replace with your actual catalog item Sys ID
    var answer = false;

    // Query the RITMs matching the given criteria
    var gr = new GlideRecord('sc_req_item');
    gr.addQuery('request', requestSysId);
    gr.addQuery('cat_item', catItemSysId);
    gr.query();
    gs.log("ROW Count for matching RITMs: " + gr.getRowCount());

    while (gr.next()) {
        var taskCount = new GlideAggregate('sc_task');
        taskCount.addQuery('request_item', gr.sys_id);
        taskCount.addAggregate('COUNT');
        taskCount.query();
        if (taskCount.next()) {
            var count = taskCount.getAggregate('COUNT');
           
            if (count > 2) {
                answer = true;
                break; // No need to check further if condition is met
            }
        }
    }
}
PreethiTiruma1_0-1720516035905.png

 

2 REPLIES 2

Zach Koch
Giga Sage
Giga Sage

What is the reasoning behind scripting this? You can do this completely OOTB without scripting. You can look up both tasks that are created, then use the Wait for Condition, and just use configuration to wait for State is Closed Complete (or your desired state), against both of them so that when one or the other closes it will move forward

 

If this information helped resolve your issue, please remember to mark response correct and thumbs up to help future community members on this information, thanks!

SAI VENKATESH
Tera Sage
Tera Sage

Hi @Preethi Tiruma1 

 

As Mentioned by @Zach Koch  Why the need of writing script for the scenario that you have mentioned and Below is the example that you can follow the procedure.

 

There is an wait option that I have mentioned in the image below You can use that.

 

cn190.PNG

 

Thanks and Regards

Sai Venkatesh