- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2017 10:44 AM
Hi,
I set out thinking that this would be a simple change, but has turned into somewhat of a nightmare. I have a Training Registration application with 3 tables. Please see the attached screen shot of the Training Class and Training Room forms relevant to the explanation below. I'm trying not to be "too busy" in my explanation of the issue, but want to provide as much information as I can to help define it. Appreciate any help you can provide.
Tables
- Training Class (u_training_class)
- Includes a Seats Available integer field(u_number_of_seats_available)
- Training Room (u_training_room)
- includes a Seats integer field (u_seats)
- Attendee (u_attendee)
When a Training Room is added to a Class record, a BR sets the Seats Available (u_number_of_seats_available) integer value to the integer value of the Seats (u_seats) from the Training Room table.
There is an Attendees Registered (u_number_of_attendees_registered) integer field on the Training Class table that increments the count of attendees as they register for the Class. It also decrements the count if an attendee is deleted. Attendees Registered number compares to the Seats Available number to determine what the Class Status should be set to.
I am trying to set the Class Status (u_class_status) field on the Training Class form based on comparison of the Attendees Registered to the Seats Available when a Class is inserted or updated. The update to the Class record would include either a seat count change on the Training Room, or a different Training Room is added to the Class.
Examples (pseudo):
- If Attendees Registered < Seats Available && Class Status != "Closed" && Class Status !="Cancelled", set Class Status to "Open"
- NOTE: This would always be the case when a new Class is created (Inserted). The current Class Status default value is "Open", but that might be causing issues with the BR running on insert and update.
- If Attendees Registered >= Seats Available && Class Status != "Closed" && Class Status !="Cancelled", set Class Status to "Full"
- NOTE: This would be the case if the Seat count is changed on the Training Room that is already added to the Class record or the Training Room itself is changed on the Class record
I have two requirements, with consideration that a new Class record will always have a Class Status of "Open":
- Set the Class Status appropriately, based on compare of seats available to attendees registered, when the Seat count (u_seats) changes on the Training Room table
- Set the Class Status appropriately, based on compare of seats available to attendees registered, when the Training Room changes on the Class Record.
The following Before BR works for requirement 1, but I can't get a BR to change the Class Status based on the same comparison conditions if a different Training Room is added to the Class record. I need to tell the BR that the Training Room has changed and execute the conditions based on the change, but because the Training Room is a reference field, I think that's why I'm struggling. I also need to ensure that every NEW Class record gets set to a Class Status of "Open".
(function executeRule(current, previous /*null when async*/) {
//Run Before to Set the Class Status if the Seat Count is changed on the Training Room
var seats = current.u_number_of_seats_available;
var attendees = current.u_number_of_attendees_registered;
if(seats > attendees){
current.u_class_status = "Open";
if(seats == attendees || seats < attendees){
current.u_class_status = "Full";
}
}
})(current, previous);
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2017 12:34 PM
Hi Mike,
When does the Business Rule executes? What are the conditions of the Business Rule? Make sure it runs when the Training Room 'Changes' also.
Hope this helps. Mark the answer as correct/helpful based on impact.
Thanks
Antin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2017 12:34 PM
Hi Mike,
When does the Business Rule executes? What are the conditions of the Business Rule? Make sure it runs when the Training Room 'Changes' also.
Hope this helps. Mark the answer as correct/helpful based on impact.
Thanks
Antin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2017 12:46 PM
Also, you have a Business Rule to calculate the Seat Available when a Room is added right? You should do the above calculations(Mentioned in your business rule) in that too.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2017 07:51 PM
Hi Antin,
I am finally getting results with the following BR that runs After and only on Update. For some reason, I wasn't getting the the BR to recognize that the Training Room (reference field) changed on the Class record. Setting the variable (trRoom) and the if(trRoom.changes() seems to be working now and I'm getting successful test results. I think all I need to do now is set the default Class Status value to "Open" for any new record inserted and all should be well.
(function executeRule(current, previous /*null when async*/) {
//Runs After on Update.
//Set Class Status to "Open" when Seats is greater than attendees registered. Set Class Status to "Full" when Seats <= attendees registered
var seats = current.u_number_of_seats_available;
var attendees = current.u_number_of_attendees_registered;
var status = current.u_class_status;
var trRoom = current.u_training_room;
if(trRoom.changes()){
if(seats > attendees && status != "Closed" && status !="Cancelled" ){
current.u_class_status = "Open";
}
if(seats <= attendees && status != "Closed" && status != "Cancelled" ){
current.u_class_status = "Full";
}
current.update();
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2017 10:14 PM