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

DrewW
Mega Sage

Have you looked at the workflow to see how it is setup?  Usually for changes I use the workflow to move the Change Stage along.

vijaykumar28
Tera Contributor

Is there a way to create a business rule to automatically run when the when a change goes into "Schedule" state, "Planned start date" automatically auto-populate today date to  run a script to  "Implement"?

Hi

 

Were you able to achieve this scenario please.

Hi,

 

I just responded to that note, are you trying to accomplish the exact same? What is your exact business need?

Hi,

 

Pretty sure it can be done, but let me know if I understand correctly.

You want to create a BR with the following conditions. On After update, condition when CR changes into the schedule state.

Then the BR will update the CR planned start date with the current date time. This would need to be scripted, but would you also want to include an update to the record to update it to the implement implement state?

 

If your doing anything with date and time you will likely need to use GlideDate or GlideDateTime if you need a specific time. There is a bunch of stuff online for GlideDate and GlideDateTime.

https://developer.servicenow.com/dev.do#!/reference/api/washingtondc/server/no-namespace/c_GlideDate...

 

If I could understand the exact business need you are trying to overcome there might be a better method.