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.

How to change the state when "due date" is reached?

berrykloes
Kilo Explorer

At this moment we have a "substate" called "Planned".

Also i have a sperated field called "Planned_Time".

Now the goal i want to achieve is that when this time is reached the "substate" will be empty and the "state" will be changed to "Assigned".

Is there anyone who has a proper script for this for the "Fuji" release?
I've tried different options from Business Rules to Workflows but none worked for me so far.

Thanks in advanced!

Berry

2 REPLIES 2

dmfranko
Kilo Guru

What did you try for a business rule?   It should be a simple matter of creating a business rule and then scheduling it to run on a given interval.


User179407
Mega Guru

Hi Berry,



I had a similar requirement to change the Incident state to Active from Pending when the Pending expiration date passed.



I have written a Scheduled job with below config


Run--> Periodically


Repeat Interval --> 5 mins



Run this script:



var gr = new GlideRecord("incident");


gr.addQuery('state', 4); // state is Pending


gr.query();



while(gr.next())


  {


  var diff = gs.dateDiff(gs.nowDateTime(), gr.u_pending_expiration.getDisplayValue(), true);



  if(diff<0){


  gr.state = 2;   // state set to Active


  gr.work_notes = "Pending Expiration time has passed";


  gr.update();


    }


}




Modify this script according to your requirement.


Hope this helps



Suraj Chauhan