Need to Sync up the REQ state based on order Guide RITMs

Negha1
Tera Contributor

Hi Community,

 I have created order guide with 18 rule bases. When I raise a request, 4 RITMs got created based on conditions set in rule base. Now When I close complete 2 RITM, 2 with Close Incomplete , i want the REQ state to become to closed Incomplete. but REQ remains in Approved.

 

Scenario is- if any one RITM becomes Closed Incomplete or closed Skipped. the main parent REQ state has to be updated to Closed Incomplete.

 

I have created a BR to achieve this, but it is not working.

 

How to achieve state sync for RITM to REQ for Order guide.

3 REPLIES 3

Dushyant Siroh
Tera Expert

Hello Neha 

 

 

I have seen your code , can you please change the code ritmGr.state = " Closed Incomplete" instead of this you will try 3, 4 ritmGr.state = " 4 "  its depend on your instance what was the value , if you will paste the code its helpful for me.

 


Regards
Dushyant Sirohi

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Negha1 

 

This is not the best practice, to sync REQ and RITM. REQ is mostly in an approved state, how the system know I need to update REQ to close complete/incomplete if out of 18, 16 are completed and 2 are incomplete? At this place, human intervention is needed every time. So Don't implement this.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Runjay Patel
Giga Sage

HI @Negha1 ,

 

You can create business rule to sync the state.

(function executeRule(current, previous /*null when async*/) {
    var parentRequest = current.request; // Get the parent REQ

    if (!parentRequest) {
        return;
    }

    // Check if ANY RITM is Closed Incomplete or Closed Skipped
    var ritmGR = new GlideRecord('sc_req_item');
    ritmGR.addQuery('request', parentRequest);
    ritmGR.addQuery('state', '7'); // Closed Incomplete
    ritmGR.addOrCondition('state', '8'); // Closed Skipped
    ritmGR.query();

    if (ritmGR.next()) { // If any matching RITM found
        parentRequest.state = '7'; // Set REQ to Closed Incomplete
        parentRequest.update();
    }
})(current, previous);

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------