
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2016 01:36 PM
I am trying to get a wait for condition to wait until any tasks state changes to 2 (work in progress)
var tasks = new GlideRecord('sc_task');
tasks.addQuery('request_item', current.sys_id);
tasks.query();
while (tasks.next()){
if(tasks.state == 2){
answer = true;
}
else{
answer = false;
}
}
/* Other Tested Code (there is only one task so thought this would also work.)
if(tasks.next()){
if(tasks.state == 2){
answer = true;
}
else{
answer = false;
}
}
else {
answer = false;
}
*/
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2016 10:58 AM
I have figured it out! let me know if this helped anyone.
the issue is when the task is updated the wait for condition doesn't cycle because it only does when the item updates. We added a business rule to force an update for the tasks item below.
Table: sc_task
When: after update
Condition: State changes
(function executeRule(current, previous /*null when async*/) {
forceReqItemUpdate();
function forceReqItemUpdate() {
var wf = new Workflow();
var ri = new GlideRecord("sc_req_item");
if (ri.get(current.request_item)) {
wf.runFlows(ri, 'update');
}
}
})(current, previous);
_________________
Then the script inside the wait for condition is
var tasks = new GlideRecord('sc_task');
tasks.addQuery('request_item', current.sys_id);
tasks.query();
//This will work for the first task in the list of tasks. In my particular workflow this is what i wanted
if(tasks.next()){
if(tasks.state == 2){
answer = true;
}
else{
answer = false;
}
}
else {
answer = false;
}
/* This should work for if you want to find any task where the state has changed to work in progress
while (tasks.next()){
if(tasks.state == 2){
answer = true;
}
}
*/

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2016 10:58 AM
I have figured it out! let me know if this helped anyone.
the issue is when the task is updated the wait for condition doesn't cycle because it only does when the item updates. We added a business rule to force an update for the tasks item below.
Table: sc_task
When: after update
Condition: State changes
(function executeRule(current, previous /*null when async*/) {
forceReqItemUpdate();
function forceReqItemUpdate() {
var wf = new Workflow();
var ri = new GlideRecord("sc_req_item");
if (ri.get(current.request_item)) {
wf.runFlows(ri, 'update');
}
}
})(current, previous);
_________________
Then the script inside the wait for condition is
var tasks = new GlideRecord('sc_task');
tasks.addQuery('request_item', current.sys_id);
tasks.query();
//This will work for the first task in the list of tasks. In my particular workflow this is what i wanted
if(tasks.next()){
if(tasks.state == 2){
answer = true;
}
else{
answer = false;
}
}
else {
answer = false;
}
/* This should work for if you want to find any task where the state has changed to work in progress
while (tasks.next()){
if(tasks.state == 2){
answer = true;
}
}
*/

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2018 01:25 AM
I am not entiery sure, but I think the solution given here:
https://community.servicenow.com/community?id=community_question&sys_id=02810369db98dbc01dcaf3231f961903
Is better:
var gr = new GlideRecord('sc_req_item');
if (gr.get(current.request_item)) {
new Workflow().broadcastEventToCurrentsContexts(gr, 'update', null);
}
Cheers
Daniel
If this answer was helpful, I would appreciate if you marked it as such - thanks!
Best
Daniel