- 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:23 AM
var tsk=new GlideRecord("sc_task");
tsk.addQuery('number','TASK0290363');
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.addQuery('sys_id',current.getValue('request_item'));
itm.query();
if(itm.next()){
itm.state= '6';
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:26 AM
By adding this line, you are checking if a specific task is in Pending, not all sibling tasks related to a common parent.
tsk.addQuery('number','TASK0290363');
Remove/comment out that line and I think you'll get better results. FWIW, if you want to avoid performance issues, consider adding
tsk.setLimit(1); before the tsk.query() as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2016 07:31 AM
you are correct, But im trying to test this code on background script
But this didnt even help in ui action without that number line

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2016 07:34 AM
To test it in a background script you will need things like 'current' defined. You can do that yourself... This short video should help you be more effective debugging using scripts background.
Faster Server Side Script Development and Test
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2016 07:39 AM
thanks chuck i understand why current isnt working.
But how to proceed here..let skip the testing part