Need to update "Change Task" state when a "Change Request" is approved

Sarah C_1
Kilo Expert

Hi. 

I'm working with Change application and currently on London.

Ultimately my goal is to differentiate the state of Change Tasks for Change Requests that are approved vs. not approved yet.  When users see Change Tasks in their queue, they don't have visibility into whether the Change Request is approved yet and therefore the user can go ahead and complete their task. 

I'm open to any suggestions on how to accomplish the above, but my potential approach is the following:

1)  Create a Business Rule to set all new Change Tasks to 'Pending' state (with the condition that the Change Request state is New, Assess, or Authorize). 

2)  When a "Change Request" is approved, I want to update the state for all "Change Tasks" within a CHG to a different state, e.g. Open. I tried creating a business rule with the following:   Table=Change Task;  When to run Filter Condition: "Change request.state 'changes to' Scheduled;  Action: set "State" to Open

My first BR above worked fine, but the second BR did not.  😞    I thought about adding a 'Set Value' to the workflow, but that seems to only function by updating values on the Change table and not the Change task table, plus there can be multiple change task records.

Please send any suggestions on how to accomplish this. 

Thanks!!

Sarah

1 ACCEPTED SOLUTION

That's ok, I didn't mention that I didn't test the code and my first attempt almost always contains typos!

I've read your questions again and modified the code a little bit.

Your previous rule didn't work because you have specified the trigger table as change task, but the trigger table is in fact change. See below:

Business Rule
Table: Change Request
When: After
Condition: State 'changes to' Scheduled

// Query all active change tasks of change
var OPEN = 1;
var childChangeTask = new GlideRecord('change_task');
childChangeTask.addQuery('change_request',current.getValue('sys_id'));
childChangeTask.addActiveQuery();
childChangeTask.query();

// Loop through all changes and update
while (childChangeTask .next()){

   childChangeTask.state = OPEN;
   childChangeTask.update();

}

 


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

View solution in original post

6 REPLIES 6

Harish KM
Kilo Patron
Kilo Patron

Sample script below to be created on Change Request table(AFTER BR).

 

Sample script below to be created on Change Request table(AFTER BR).

 

var gr = new GlideRecord('change_task');
gr.addQuery('change_request',current.sys_id);
gr.query();
if(gr.next()){
if(current.state = 'PASS CHOICE VALUE')
{
gr.state = '1'; //change task state
}

if(current.state = 'approved value')
{
gr.state = ""3;//what ever task change u want to change
}
}
gr.update();

 

Regards
Harish

You need the gr.update() to be in the scope of the IF statement, otherwise, an empty change task record will be inserted when there are no Change Tasks (update will insert if the record is new)

var gr = new GlideRecord('change_task');
gr.get('change_request',current.sys_id);

if(gr.isValidRecord()){
   if(current.state = 'PASS CHOICE VALUE') {
      gr.state = '1'; //change task state
   }
 
   if(current.state = 'approved value') {
      gr.state = ""3;//what ever task change u want to change
   }

   gr.update();
}

ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

Thanks for the reply!  Can you check the syntax of your script?  I'm getting some errors.  Also, I forgot to mention that I don't have any scripting knowledge, so forgive me if I'm missing something obvious.  🙂  Thanks again!

That's ok, I didn't mention that I didn't test the code and my first attempt almost always contains typos!

I've read your questions again and modified the code a little bit.

Your previous rule didn't work because you have specified the trigger table as change task, but the trigger table is in fact change. See below:

Business Rule
Table: Change Request
When: After
Condition: State 'changes to' Scheduled

// Query all active change tasks of change
var OPEN = 1;
var childChangeTask = new GlideRecord('change_task');
childChangeTask.addQuery('change_request',current.getValue('sys_id'));
childChangeTask.addActiveQuery();
childChangeTask.query();

// Loop through all changes and update
while (childChangeTask .next()){

   childChangeTask.state = OPEN;
   childChangeTask.update();

}

 


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022