automatically set REQ to closed complete when RITM is closed complete

lmao
Tera Contributor

**updated script below, had to change "closed_complete" to "3" for the sc_req_item (for sc_request it is not numeric). unfortunately it still does not work**

 

hello, i have created a BR for closing a REQ as soon as the RITM is closed. According to the BR Debugger, it is doing something but there is no outcome visible on the REQ status.

I would be interested if anyone can see where is the error. I will attach the BR i have created:

 

lmao_0-1693827337505.png

 

 

(function executeRule(current, previous) {
    // first checking the RITM status
    if (current.state == 'closed_complete') {
        // then dot-walk to the REQ status
		
        var parentRequest = new GlideRecord('sc_request');
        
        if (parentRequest.get('number', current.request)) {
            // Update the parent request's status to closed
            parentRequest.request_state = 'closed_complete';
            parentRequest.update();
        }
    }
} 
)(current, previous);

 

 

**new script:**

 

(function executeRule(current, previous) {
    // first checking the RITM status
    if (current.state == '3') {
        // then dot-walk to the REQ status
		
        var parentRequest = new GlideRecord('sc_request');
        
        if (parentRequest.get('number', current.request)) {
            // Update the parent request's status to closed
            parentRequest.request_state = 'closed_complete';
            parentRequest.update();
        }
    }
} 
)(current, previous);

 

 

1 ACCEPTED SOLUTION

Vishal Birajdar
Giga Sage

Hi lmao,

 

Instead of 'number' you should use sys_id and current.state == '3'

 

(function executeRule(current, previous) {
// first checking the RITM status
if (current.state == '3') {
// then dot-walk to the REQ status

var parentRequest = new GlideRecord('sc_request');

if (parentRequest.get('sys_id', current.request)) {
// Update the parent request's status to closed
parentRequest.request_state = '3';
parentRequest.update();
}
}
}
)(current, previous); 

  

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

View solution in original post

6 REPLIES 6

Vishal Birajdar
Giga Sage

Hi lmao,

 

Instead of 'number' you should use sys_id and current.state == '3'

 

(function executeRule(current, previous) {
// first checking the RITM status
if (current.state == '3') {
// then dot-walk to the REQ status

var parentRequest = new GlideRecord('sc_request');

if (parentRequest.get('sys_id', current.request)) {
// Update the parent request's status to closed
parentRequest.request_state = '3';
parentRequest.update();
}
}
}
)(current, previous); 

  

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

thank you, it works now! 👍