Based on work order state need to close Ritm

varma2
Mega Sage

Hi All,

 

We have a catalog item, in that variable which is ( work order number ) when we select variable work order number   and submit the REQUEST and  that RITM  should set in that selected variable work order.

 

when we close and canceled the workorder that ritm also should close.

 

Please suggest.

 

Thanks all,

 

3 REPLIES 3

Rajesh Chopade1
Mega Sage

Hi @varma2 

You can achieve this by using a combination of Business Rules and possibly a Script Include.

1) You will need a Business Rule to capture the RITM when the catalog item is submitted.

- create BR (after Insert) on sc_req_item table which link RITM to work order

- add condition as - current.work_order_variable.changes() && current.work_order_variable != '';

- BR script:

// Assuming work_order_variable is the name of the variable
var workOrder = current.work_order_variable; // Get the Work Order number
if (workOrder) {
    // Set the RITM's Work Order field
    current.work_order = workOrder; // Adjust based on your field name
}

 

2) create a Business Rule to monitor the Work Order table for closure or cancellation.

- create BR (after update) on 'Your Work Order Table ' table 

- conditions - current.state.changes() && (current.state == 'Closed' || current.state == 'Canceled');

- BR script:

// Assuming 'work_order' is a reference to the Work Order in the RITM
var ritmGR = new GlideRecord('sc_req_item');
ritmGR.addQuery('work_order', current.sys_id); // Adjust based on your field name
ritmGR.query();

if (ritmGR.next()) {
    ritmGR.setValue('state', 'Closed'); // Set to Closed (or your custom closed state)
    ritmGR.update(); // Update the RITM
}

 

i hope my answer helps you to resolve your issue, if yes please mark my answer helpful and correct.

thank you

rajesh

HI @Rajesh Chopade1 ,

 

i need to achieve this through workflow.

 

Thank you.

Ok, follow bellow steps then

- You should follow above mentioned BR to capture work order number when RITM created. 

- Configure workflow on Your Work Order Table 

- Drag a Condition activity to check if the Work Order state is changing

current.state.changes() && (current.state == 'Closed' || current.state == 'Canceled');

-Drag a Run Script activity to close the associated RITM

var ritmGR = new GlideRecord('sc_req_item');
ritmGR.addQuery('work_order', current.sys_id); // Adjust based on your field relationship
ritmGR.query();

while (ritmGR.next()) {
    ritmGR.setValue('state', 'Closed'); // Replace 'Closed' with your closed state if necessary
    ritmGR.update(); // Update the RITM
}

- Save and publish workflow.