What is current and previous in ServiceNow business rule

ST9
Tera Contributor

Can someone explain me what current and previous in servicenow business rule with examples. 

1 ACCEPTED SOLUTION

Anil Lande
Kilo Patron

Hi,

As you know business rule execute when CRUD operations happen on any record.

When before and After Business rule is running it gets two copy of the record which is changed.

Previous is a copy of same GlideRecord object storing old values (Original copy)

Current is copy of GlideRecord object storing New values (Updated copy)

For Example:

When you opened any incident it was having state as new and Assigned to empty (This will be your Previous copy). Now you changed state and assigned_to fields and saved form (This is updated i.e current copy).

If you try to log below lines for above example :

gs.info(previous.state);  // it will print new (i.e 1)

gs.info(previous.assigned_to);  // it will print nothing (assihnedto was empty)

 

gs.info(current.state);  // it will print In Progress (i.e 2)

gs.info(current.assigned_to);  // it will print sys_id of assigned_to user

 

 

Thanks,
Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

View solution in original post

6 REPLIES 6

SaschaWildgrube
ServiceNow Employee
ServiceNow Employee

To identify the business rules and flows that run on a record when inserting, updating, deleting, displaying or querying the record the DevTools' WhatRuns button comes in handy.

As the name suggests it shows you what runs on a record (including business rules on parent tables).

DevTools contains a truckload of re-usable functions and features for developers.

Fork at will:

https://github.com/saschawildgrube/servicenow-devtools

VaranAwesomenow
Mega Sage

I made a 2 part video providing details, examples and possible pitfalls and fixes.

https://youtu.be/0wYZezSL6Ss