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:33 PM
Hi there,
If just interested in a previous value, just use something like:
previous.getValue("u_string_1")
There's no need to use "getElement".
Note: previous does not work on async business rules.
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-06-2020 11:36 PM
Mark, we tried with that syntax also but its not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2020 11:42 PM
Hi Dinesh,
try using below updated code
I have just used previous.u_string_1 and previous.u_room_status
(function executeRule(current, previous /*null when async*/) {
var v = new GlideRecord('u_meeting_booking_details');
var prev1 = previous.u_string_1;
gs.addInfoMessage(prev1);
var prev2 = previous.u_room_status;
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 ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2020 11:59 PM
Ankur, Its still not working. Infomessage still does not diplays the previous value. It is still empty.