- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2023 12:53 AM
I am running a job to check for a state value that is on On Hold and the date given in a particular field matched todays date, then set the state field back to the previous value (i.e. state value which was before On Hold).
Please suggest.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2023 01:08 AM
Hi,
A simple solution would be to create custom field 'Previous state' on your table and set the value of this field using BR on State change.
A BR would be:
When - Before Insert/Update (condition = state changes)
use below line in script part
current.u_previous_state = previous.state;
This will track the previous state and you can use it in your scheduled job.
Thanks
Anil Lande

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2023 01:45 AM
Hi,
You can use History walker in script part.
You can use something like this:
var incGr = new GlideRecord('incident');
incGr.get('number', 'INC0000015'); // replace your query here
var currentState = incGr.state;
var oldState =incGr.state;
var hw = new sn_hw.HistoryWalker(incGr.getTableName(), incGr.getUniqueValue());
hw.walkTo(incGr.sys_mod_count);
do {
oldState = hw.getWalkedRecord().state;
} while (hw.walkBackward() && currentState !=oldState )
this will give you old state.
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2023 02:00 AM
@Anil Lande - Use this script in Flow designer or Scheduled Job?
Will it have any performance issues? As I checked HistoryWalker API uses the audit/history tables to generate a historical version of an existing record, and this table is really really huge, and query to this table is a real threat to the performance.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2023 02:16 AM
Hi,
If you are using flow the you can create Flow variable and set the value of Flow variable using above script.
If you are using scheduled job then you can use above script in your scheduled job to get previous value of incident.
Now there is no other way to get previous state, This is official API and we can use it. I don't see any issue. You can try running some script for limited no of tickets and see if it cause any performance issue.
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2023 04:36 AM
@Anil Lande - Thanks for this info, I am opting for the first approach you suggested which is creating a custom field.