Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Incident State from "on hold" to "in Progress"

Steve2000
Tera Contributor

I want to change regularly all "on Hold" Incidents and where the "follow up" fields are exceeded that the field values of "follow up" are cleared and the "State" changes to "in Progress" 

Also I want to fill in a Work Note saying "The Incident changed to "in Progress" because the "Follow Up" is exceeded.

 

I´m a rookie with this platform and I´m overwhelmed by the possibilities of this platform 🙂

I´m very thankful in advance 🙂

2 ACCEPTED SOLUTIONS

RaghavSh
Mega Patron

You can run a scheduled job daily (or as per your convenience)  for this with below code:

var inc = new GlideRecord('incident');
inc.addEncodedQuery('state=3^follow_up<javascript&colon;gs.beginningOfToday()'); // will fetch on hold incident with follow up date before today, so when it will run daily, all incidents will be covered.
inc.query();
while(inc.next())
{
inc.state=2;
inc.update();
}

 Note: All scripts should be tested in dev before execution in prod.


Raghav
MVP 2023
LinkedIn

View solution in original post

Scheduled job, which will run daily. (sysauto) table.

Screenshot 2022-12-19 at 4.58.03 PM.png

For more info refer : https://docs.servicenow.com/en-US/bundle/tokyo-platform-administration/page/administer/reference-pag... 


Raghav
MVP 2023
LinkedIn

View solution in original post

5 REPLIES 5

sushma9
Tera Contributor

@RaghavSh 

When i am running the schedule job for every 5 mints its not working for me and state of the incident is not changing to in progress .  Please find the attached screen shots along with logs . Please let me know if anything has to be modified in the script 

 Script :  

var s= new GlideRecord("incident");
    s.addEncodedQuery("state=3^sys_updated_on<javascript&colon;gs.beginningOfToday()");
    gs.info("hello 3");
    s.autoSysFields(false); // use if you don't want update system fields
    s.setWorkflow(false);
    gs.info("hello4");
    s.query();
    while(s.next())
        {
            s.setValue("state",2);
            s.update()
            gs.info("hello5");
        }

sushma9_0-1699148618094.png

sushma9_1-1699148656751.png

 

sushma9_2-1699148711874.png