business rule error - Help from a helpful community member required ;o)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2023 01:45 PM
I was hoping someone could be my 2nd pair of eyes and point out my error. Ill provide the code to business rule below, when the business rule triggers its providing this error in the log.
'Unable to retrieve room type record for booking undefined' for the love of me I cant figure it out.
The Business rule is as follows- Runs before on insert/update
(function executeRule(current, previous) {
// Get the room type record corresponding to the booking record
var roomType = new GlideRecord('sn_hbm_room_type');
if (roomType.get(current.room_type.name)) {
// Get the price and number of nights from the booking record
var price = parseFloat(roomType.getValue('price'));
var numberOfNights = parseInt(current.getValue('number_of_nights'));
// Calculate the total cost
var totalCost = price * numberOfNights;
// Set the value of the total cost field on the current record
current.total_cost = totalCost;
// Log the total cost calculation
gs.log('Total cost for booking ' + current.number + ' is ' + totalCost);
} else {
gs.log('Unable to retrieve room type record for booking ' + current.number);
}
})(current, previous);
The room type table has a field named 'name' which is a name field and field called 'Price which is of a pricetype'. Im trying to capture that price of the room to then multiple it by the number of nights booked. driving me insane for the past few days. Thanks for looking all.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2023 04:21 PM
hi,
what specific table is the business rule defined on, it has a reference field named 'room_type', and where does the 'sn_hbm_room_type' table come from? Knowing this will help in some here understand what you're trying to do.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2023 09:45 PM
Hi,
Based on the error message you provided, it seems like the issue is with the "current.room_type.name" value. It might be undefined or not set properly, which is causing the GlideRecord query to fail.
To fix this issue, you can check if the "current.room_type" field is not null and is valid before querying the "sn_hbm_room_type" table. You can also add some error handling to log any errors that might occur during the query.
Here's the updated business rule code:
(function executeRule(current, previous) {
if (current.room_type && current.room_type.name) {
// Get the room type record corresponding to the booking record
var roomType = new GlideRecord('sn_hbm_room_type');
if (roomType.get('name', current.room_type.name)) {
// Get the price and number of nights from the booking record
var price = parseFloat(roomType.getValue('price'));
var numberOfNights = parseInt(current.getValue('number_of_nights'));
// Calculate the total cost
var totalCost = price * numberOfNights;
// Set the value of the total cost field on the current record
current.total_cost = totalCost;
// Log the total cost calculation
gs.log('Total cost for booking ' + current.number + ' is ' + totalCost);
} else {
gs.log('Unable to retrieve room type record for booking ' + current.number);
}
} else {
gs.log('Room type is not set or invalid for booking ' + current.number);
}
})(current, previous);
Thanks,
Rahul Kumar
Thanks,
Rahul Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2023 02:01 AM
Please accept the solution and closed the thread. If it's working for you.
Thanks,
Rahul Kumar