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-07-2020 12:02 AM
Hi Dinesh,
What type of business rule it is?
Regards
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-07-2020 02:44 AM
It is after business rule.
I want it for room booking application. I have 3 fields here named as
u_add_room, u_string_1 (availibility), u_room_status......... I want to update availibility and room status value based on previous data of those respected fields.
For Eg: In the attachment if u see the add room is "volga" the previous availability value is "yes" and room_status value is "no". if the user again selects the add room as "volga" i want to change the current value of availibility as "no" and room status as "yes". But i m unable to do it because i m not able to get the previous value.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2020 11:43 PM
previous should work fine.
So what exactly is not working? Is the gs.addInfoMessage(prev1); not working? If you write prev1 to the logs, what do you get?
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:57 PM
info message for prev1 is not working. it does not displays any values .it is still empty.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2020 11:45 PM
Also note:
previous.getvalue("u_room_status");
getvalue: this at leats has to be getValue. With a uppercase.
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