Wait for condition Script in workflow

Madhuchhanda
Tera Expert

Hi all,

I have wait for condition and it should work when the status is 'closed complete' or 'closed incomplete' or 'closed skipped'. But my script is not working and my tasks are in parallel. But I can't use join.

Below is my script :-

checkCatalogTasks();

function checkCatalogTasks() {

var grTask = new GlideRecord('sc_task');

            var Task = gr.addQuery('request_item', current.sys_id);

            Task.addOrCondition('active', true);

            Task.addOrCondition('state', '!=', '3');

            Task.addOrCondition('state', '!=', '4');

            Task.addOrCondition('state', '!=', '7');

grTask.query();

if(grTask.hasNext()){

answer = false;

}

else{

answer = true;

}

}

Please help. Thanks in advance.

7 REPLIES 7

Brian Lancaster
Tera Sage

Instead of using addorcondition why don't you do something like.

grTask.addQuery('state', 'NOT IN', '3,4,7');

I also don't think you need to check if that task is active because it would never be active once that state is closed.  So it would look like this instead.

checkCatalogTasks();

function checkCatalogTasks() {

var grTask = new GlideRecord('sc_task');

grTask.addQuery('state', 'NOT IN', '3,4,7');

 

grTask.query();

if(grTask.hasNext()){

answer = false;

}

else{

answer = true;

}

}

Also instead of if (grTask.hasNext()) try if (grTask.next())

Archana Reddy2
Tera Guru

Hi Madhu,

If it is not your typo here, below is something you need to modify.

Replace gr with grTask in line4 of your script.

Also, may I know why you are using Task variable while you already have grTask variable?

Hope this helps!

Thanks,

Archana

Inactive User24
Mega Expert

Hi Madhu,

Instead of using script, you can make use of the check box "wait for completion"

I have attached a screnshot for reference.