The "State" field (not Request State") in request doesn't change when all RITM are completed

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2017 09:07 AM
The "State field is not updated when all RITM are closed and completed for the Request . The Request itself is "Closed Completed" and not active anymore but the State field isn't. I am thinking about writing a Business Rule. It is the right approach? What would that script look like? I am new to SN and my scripting skills are getting better but still not there where I want them to be. Any help is appreciated.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2017 09:09 AM
I am from. Mobile can't check properly. But I think you can meanwhile check business rule for this. There must be some business rule which is responsible for auto closure of request once all ritm are completed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2017 09:10 AM
Can you also check the dictionary entry of state. That also may be the reson
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2017 09:28 AM
I had the same issue and created a business rule to update the request. This is the script we use on an "after" "update" business rule on the Requested Item table, with the condition: Active is false and State changes. (There might be a more elegant script out there, but this was one of the first I wrote):
(function executeRule(current, previous /*null when async*/) {
gs.info(current.number + ' trying to close request');
var comp = 0;
var incomp = 0;
var skip = 0;
var op = 0;
var tot = 0;
var ri = new GlideRecord('sc_req_item');
ri.addQuery('request',current.getValue('request'));
ri.query();
while(ri.next()){
tot += 1;
gs.info(current.number + ' found requested items ' + ri.number + 'and total is ' + tot);
if(ri.state == 3){
comp += 1;
gs.info(current.number + ' comp is ' + comp);
}
else if(ri.state == 4){
incomp += 1;
gs.info(current.number + ' incomp is ' + incomp);
}
else if(ri.state == 7){
skip += 1;
gs.info(current.number + ' skip is ' + skip);
}
else{
op += 1;
gs.info(current.number + ' op is ' + op);
}
}
var req = new GlideRecord('sc_request');
req.addQuery('sys_id',current.getValue('request'));
req.query();
if(req.next()){
if(tot == comp){
req.state = 3;
gs.info('Close request as complete');
}
else if(tot == skip){
req.state = 7;
gs.info('Close request as skipped');
}
else if(op != 0){
req.state = 1;
gs.info('Keep request open');
}
else{
req.state = 4;
gs.info('Close request as incomplete');
}
req.update();
}
})(current, previous);