Set RITM to Pending if any linked SCTask is set to Pending

steveturley
Tera Guru

I need for the linked RITM to be set to 'Pending' when any of the associated SCTasks are set to 'Pending'

 

When none of the associated SCTasks are pending, the RITM needs to move back to 'Work in Progress'

 

Can anyone help please?

 

Thanks!

1 ACCEPTED SOLUTION

@steveturley 

After BR on SCTask table 

Conditions

State changes from pending

and request_item.state is not WIP

On insert and update

 

in advance Script

 

var task = new GlideRecord('sc_task');

task.addQuery('request_item',current.request_item);

task.addQuery('state','-5');// replace back end value mostly it will be numeric value

task.query();

if(task.next()){

//do nothing

}else{

var gr = new GlideRecord('sc_req_item');

gr.get(current.request_item);

gr.state = 'WIP';// replace back end value mostly it will be numeric value

gr.update();

}

 

My bad that should be not != just pending try above code

If my inputs have helped with your question, please mark my answer as accepted solution, and give a thumb up.
Bharath Chintala

View solution in original post

6 REPLIES 6

BharathChintala
Mega Sage

@steveturley 

Scenaro -1 :

you can write After business rule on SCTask table

conditions 

SCTask state changes to pending and

request_item. state is not pending

 

on insert and update

 

in advanced script

 

var gr = new GlideRecord('sc_req_item');

gr.get(current.request_item);

gr.state = 'pending';// replace back end value mostly it will be numeric value

gr.update();

 

Scenario 2:

After BR on SCTask table 

Conditions

State changes from pending

and request_item.state is not WIP

On insert and update

 

in advance Script

 

var task = new GlideRecord('sc_task');

task.addQuery('request_item',current.request_item);

task.addQuery('state','!=','pending');// replace back end value mostly it will be numeric value

task.query();

if(task.next()){

//do nothing

}else{

var gr = new GlideRecord('sc_req_item');

gr.get(current.request_item);

gr.state = 'WIP';// replace back end value mostly it will be numeric value

gr.update();

}

 

 

If my inputs have helped with your question, please mark my answer as accepted solution, and give a thumb up.
Bharath Chintala

Hi, thanks for the reply

 

Scenario 1 works perfectly - thanks!

 

Scenario 2 doesn't work at the moment. I change the sc_task state from 'pending' but the RITM state doesn't change.

I amended the values for 'pending' & 'WIP'. Screenshot attached

 

 

@steveturley 

After BR on SCTask table 

Conditions

State changes from pending

and request_item.state is not WIP

On insert and update

 

in advance Script

 

var task = new GlideRecord('sc_task');

task.addQuery('request_item',current.request_item);

task.addQuery('state','-5');// replace back end value mostly it will be numeric value

task.query();

if(task.next()){

//do nothing

}else{

var gr = new GlideRecord('sc_req_item');

gr.get(current.request_item);

gr.state = 'WIP';// replace back end value mostly it will be numeric value

gr.update();

}

 

My bad that should be not != just pending try above code

If my inputs have helped with your question, please mark my answer as accepted solution, and give a thumb up.
Bharath Chintala

Hi @BharathChintala 

 

I replaced the code but it doesn't work unfortunately. The RITM remains in state 'pending'.

 

Thanks

Steve