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:15 AM
Could you explain a bit what the functional case is?
Because, you are performing a GlideRecord query, performing a while, etc.. Though actually, you are updating the current record? Not for example the GlideRecord retrieved records.
Feels like a mix up of logic in your script.
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 02:42 AM
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-07-2020 02:45 AM
Performing a GlideRecord query does not give you a previous value. So you are a bit on wrong track here. Also like I mentioned, you are mixing GlideRecord and current.
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 02:53 AM
so could u please tell me how to get a previous value?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2020 04:25 AM
There is no previous value on the current record, because you are only opening the record.
I can imagine you mean a previous value like you can find in the audit (if audit is enabled). Though is that correct to check? Sounds a bit strange to me. Also, what if a other user has the same record open at the same time? How are you handling a conflict like that?
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