The CreatorCon Call for Content is officially open! Get started here.

Update state for change with business rule automatically`

Jacob23
Mega Guru

Hi, thanks for taking the time to read. I will explain what is happening and what I was thinkning to do.

find_real_file.png

The above states are from Change. When a change has been approved this goes into the "Schedule" state, then when the "Planned start date" comes true it moves over to the "Implement" state automatically. Once completed we then manually move across to review/closed rather than waiitng for the automated process.

The issue I am encountering and I think is an out of the box functionailty of ServiceNow is when a Change record has been fully approved after the "Planned start date". The Change record will move into the Schedule state and not move into the "Implement" state, unless manually done.

Is there a way to create a business rule to automatically run when the when a change goes into "Schedule" state, "Planned start date" has already passed, to then run a script to move the state into "Implement"?

I created an async business rule when a record is inserted/updated with the following conditions:

find_real_file.png

I have only just started learning to code. I tried a couple of scripts I peiced together below is one of them, which of course didnt work.

var chg = new GlideRecord('change_request');
    
    chg.get(current.change_request);
    chg.state = -1;
    chg.update();

Thanks for the help!!

1 ACCEPTED SOLUTION

Dan H
Tera Guru

Hi,

Your business rule script simply needs to be:

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

	current.state = -1;

})(current, previous);

find_real_file.png 

You're already on the change_request table (defined by the business rule), so no need for Glide Record query

You could also avoid scripting all together and just change the state via the business rules action tab 

 

Hope this helps.

Please mark my answer as Correct/Helpful based on impact

Regards,

Dan H

View solution in original post

9 REPLIES 9

Dan H
Tera Guru

Hi,

Your business rule script simply needs to be:

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

	current.state = -1;

})(current, previous);

find_real_file.png 

You're already on the change_request table (defined by the business rule), so no need for Glide Record query

You could also avoid scripting all together and just change the state via the business rules action tab 

 

Hope this helps.

Please mark my answer as Correct/Helpful based on impact

Regards,

Dan H

Thanks for the help. The code was correct but I had to set it as Async. I was also not able to get this working via the actions tab.

dmathur09
Kilo Sage

Hi Jacob,

Can you change the condition to state changes to Scheduled.

You do not require to script anything here.

Use the OOB actions tab and put the set field value as state to Implement.

Regards,

Deepankar Mathur

 

_ChrisHelming
Tera Guru

The idea of it being a manual process is to have a record of who is doing the work and when they're actually starting it. If the person implementing is out sick and their change automatically moves to implement, that could be confusing for other users.

If you use Teams or Slack, what about using an actionable notification to the implementer that their change is ready to be implemented with a button for them to change the state?