- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2016 06:49 AM
How to find all the task(sc_task) under ritm table whose state is say pending .I want this to be reflected in the parent(ritm )[the state of ritm also changes to pending] only if ALL are pending ,else ritm stays in the same state like previously it was.
piece of my code:
var tsk=new GlideRecord("sc_task"); |
tsk.addQuery('request_item',current.request_item);
tsk.query();
while(tsk.next()){ | ||
if(tsk.state=="6") | { | |
var itm= new GlideRecord("sc_req_item");
itm.addQuery('sys_id',current.request_item);
itm.addQuery('active',true);
itm.query();
if(itm.next()){
itm.state= '6';//also has the same value to avoid confusion.
itm.update();
gs.addInfoMessage(itm.number+itm.state.getDisplayValue());
} | |
} |
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2016 06:58 AM
here you go. This should be an after business rule on sc_task table.
var tsk=new GlideRecord("sc_task");
tsk.addQuery('request_item',current.getValue('request_item'));
tsk.addQuery('state','IN','6');
tsk.query();
if(tsk.hasNext()){
var itm= new GlideRecord("sc_req_item");
itm.get(current.getValue('request_item'));
itm.state= '6';//also has the same value to avoid confusion.
itm.update();
gs.addInfoMessage(itm.number+itm.state.getDisplayValue());
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2016 07:41 AM
I'm afraid I don't understand. Are you trying to test in scripts background or not? I lost track.
If you are having issues, then testing is the best way to find any bugs and understand the results returned.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2016 07:41 AM
See my responses on how to test and how to proceed

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2016 07:36 AM
Put this code in an after business rule. If you want to test it in background scripts, there is no current defined. You need create a current record. Use this in the background scripts
var current= new GlideRecord('sc_task');
current.get('number','TASK0290363');
var tsk=new GlideRecord("sc_task");
tsk.addQuery('request_item',current.getValue('request_item'));
tsk.addQuery('state','IN','6');
tsk.query();
if(tsk.hasNext()){
var itm= new GlideRecord("sc_req_item");
itm.get(current.getValue('request_item'));
itm.state= '6';//also has the same value to avoid confusion.
itm.update();
gs.addInfoMessage(itm.number+itm.state.getDisplayValue());
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2016 07:30 AM
It should work. I have tested this on my instance. Make sure you have a state choice value of 6. Out of box pending choice value is -5. I have used this code on my instance.
var tsk=new GlideRecord("sc_task");
tsk.addQuery('request_item',current.getValue('request_item'));
tsk.addQuery('state','IN','-5');
tsk.query();
if(tsk.hasNext()){
var itm= new GlideRecord("sc_req_item");
itm.get(current.getValue('request_item'));
itm.state= '-5';//also has the same value to avoid confusion.
itm.update();
gs.addInfoMessage(itm.number+itm.state.getDisplayValue());
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2016 07:02 AM
If you select the 'wait for completion' checkbox on the create task activity, you don't need a extra to wait for tasks to close.