Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Craig Gruwell
Mega Sage

Check your sys_choice records for table=sc_req_item and element=state as the values are numerical.

 

Try updating...

if (current.state == 'closed_complete') {

to

if (current.state == '3') {

 

 

thank you for the help, it was indeed incorrect. i have set it to '3' now but it still doesnt work

Mudit_Singh
Tera Contributor

hi, @lmao seems that you haven't used the backend value of "closed_complete" i.e. '3' 

use current.state=='3'

Hope this answer helps, give it a thumbs up if it works!!

lmao
Tera Contributor

Hello @Mudit_Singh  indeed the value is numeric and i set it to '3' now but unfortunately still no outcome...