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

MattSN
Mega Sage
Mega Sage

current and previous

Business Rules often use the current and previous objects in their script logic.

The current object is automatically instantiated from the GlideRecord class. The current object's properties are all the fields for a record and all the GlideRecord methods. The property values are the values as they exist in the runtime environment.

The previous object is also automatically instantiated from the GlideRecord class. The previous object's properties are also all fields from a record and the GlideRecord methods. The property values are the values for the record fields when they were loaded from the database and before any changes were made. The previous object is not available for use in async Business Rules.

 

https://developer.servicenow.com/dev.do#!/learn/learning-plans/quebec/new_to_servicenow/app_store_le...

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

ST9
Tera Contributor

Thanks Anil,

Now I've a clear picture 🙂

Glad to know my answer was helpful. Could you please close this question by marking a response as correct answer? It will be helpful for other community members to refer correct solution. Happy Learning 🙂
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