Assistance with Business Rule

TEdwards
Kilo Sage

Hello all,

 

I am have a requirement to set the state of the RITM to a certain value when the state on an SCTASK changes, but only if none of the other SCTASKs on the RITM are in an on hold state. I have tried various things in my business rule, but can't seem to wrap my head around the logic enough to make it work correctly. If anyone can assist it would be appreciated.

 

1 ACCEPTED SOLUTION

Siddhesh Gawade
Mega Sage
Mega Sage

Hello @TEdwards ,

 

Create a business rule on sc_task table. as below and add condtion as "state changes".

SiddheshGawade_0-1706894612046.png

 

 

 

(function executeRule(current, previous /*null when async*/) {

// Query the sc_task table for tasks related to the current RITM and are not on hold
var task = new GlideRecord('sc_task');
task.addQuery('request_item', current.request_item);
task.addQuery('state','-5');    // check the value of on hold choice value
task.query();

// If no other tasks are on hold, set the RITM state to 'Work in Progress'
if (!task.next()) {
var ritm = new GlideRecord('sc_req_item');
if (ritm.get(current.request_item)) {
ritm.state = '1';   // update to state value that you want as per your business requirement
ritm.update();
}
}else{
	// Do something if required
}

})(current, previous);

 

 

Kindly mark the answer ✔️Correct or Helpful ✔️If it addresses your concern.


Regards,

Siddhesh

 

View solution in original post

3 REPLIES 3

Siddhesh Gawade
Mega Sage
Mega Sage

Hello @TEdwards ,

 

Create a business rule on sc_task table. as below and add condtion as "state changes".

SiddheshGawade_0-1706894612046.png

 

 

 

(function executeRule(current, previous /*null when async*/) {

// Query the sc_task table for tasks related to the current RITM and are not on hold
var task = new GlideRecord('sc_task');
task.addQuery('request_item', current.request_item);
task.addQuery('state','-5');    // check the value of on hold choice value
task.query();

// If no other tasks are on hold, set the RITM state to 'Work in Progress'
if (!task.next()) {
var ritm = new GlideRecord('sc_req_item');
if (ritm.get(current.request_item)) {
ritm.state = '1';   // update to state value that you want as per your business requirement
ritm.update();
}
}else{
	// Do something if required
}

})(current, previous);

 

 

Kindly mark the answer ✔️Correct or Helpful ✔️If it addresses your concern.


Regards,

Siddhesh

 

Thank you so much for your help, Siddhesh. I have been going in circles for a while on this, and your solution was perfect.

@TEdwards Glad to help 😊