Wait for condition, if a task is "closed complete" or "pending"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 01:20 PM - edited 03-11-2024 01:48 PM
Hello, im currently trying to script in a wait for condition advanced settings, if tasks are state = "closed complete" or "pending" then to proceed in the wf. any ideas? i seem to cant find an example in community to fit my needs, thank you in advance
i currently have
var ActTasks = new GlideRecord("sc_task");
ActTasks.addQuery('state');
if ActTasks == 'Closed Complete' || 'Pending'){
answer = true;
}else {
answer= false;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 01:55 PM
Hi @HenryD ,
If your workflow is running on the sc_task table
ifscript()
function ifScript() {
if (current.state== 'Closed Complete' ||current.state=='pending' ) {
return 'yes';
return 'no';
}
(or)
ifscript()
function ifscript(){
var ActTasks = new GlideRecord("sc_task");
ActTasks.addQuery('sys_id', current.sys_id);//update query according to your requirement
ActTasks.query();
if (ActTasks.state == 'Closed Complete' ||ActTasks.state =='Pending'){//update state field name on your table
retrun true;
}else {
retrun false;
}
}
If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!
Thanks & Regards,
Sumanth Meda
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 05:59 PM
Hello, i tried the bottom one cause i wasnt in the sc_task table, im in the "wait for condition" activity, advanced script. I have tried this but it is still getting stuck.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 10:44 PM
Hi @HenryD ,
If we are using the same table as the wf table, then only wait for condition will wait till it meets the condition. If it is other table, it will check only once when the activity is started. It will not check again, even if the value changes are expected .
Thanks,
Deborah Brown
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 08:20 PM
Please try with below code:
var answer = false; // Initialize the answer variable as false
var ActTasks = new GlideRecord("sc_task");
// Add a query condition to filter tasks with state 'Closed Complete' or 'Pending'
ActTasks.addEncodedQuery('stateIN-5,3'); // Pending, closed complete
// Execute the query
ActTasks.query();
if (ActTasks.next()) {
// If there are records (tasks) found with the specified states, set answer to true
answer = true;
}
// Now the variable 'answer' holds true if there are tasks with state 'Closed Complete' or 'Pending', false otherwise
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks