How to get the previous value of the field in Business rule?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2020 11:29 PM
We want to update the value of the current field depends on the value of the previous field .
(function executeRule(current, previous /*null when async*/) {
var v = new GlideRecord('u_meeting_booking_details');
var prev1= previous.getvalue("u_string_1"); // unable to get the value using this syntax
gs.addInfoMessage(prev1);
var prev2= previous.getvalue("u_room_status"); // unable to get the value using this syntax
gs.addInfoMessage(prev2);
v.query();
while(v.next())
{
if(current.u_add_room == "volga"){
if(prev1 == "yes")
{
current.setValue("u_string_1","no");
current.setValue("u_room_status","yes");
}
else
{
current.setValue("u_string_1","yes");
current.setValue("u_room_status","no");
}
}
current.update();
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2020 11:57 PM
I corrected it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2020 12:08 AM
Hello,
You have written current.update() in business rule.which is not best practice
And What is the use of var v = new GlideRecord('u_meeting_booking_details'); That you have written
What is your requirement?
Which type of business rule you have written..?(before,after,async etc)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2020 02:29 AM
I want to update the value. hence i wrote current.update(). and i m write after business rule.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2020 02:32 AM
Ah so you are actually not after current.update() though after v.update()?
So is it also look you are after the previous value of the u_meeting_booking_details record? Instead of the previous value of current?
Or on what table is your business rule actually running?
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2020 04:15 AM
Hello Dinesh,
If you are making changes on the current table then i would suggest go for Before Business rule.
And Try Like This
(function executeRule(current, previous /*null when async*/) {
var prev1= previous.getvalue("u_string_1");
var prev2= previous.getvalue("u_room_status");
if(current.u_add_room == "volga"){
if(prev1 == "yes")
{
current.setValue("u_string_1","no");
current.setValue("u_room_status","yes");
}
else
{
current.setValue("u_string_1","yes");
current.setValue("u_room_status","no");
}
}
})(current, previous);