Displaying a subset of calendar events based on a selection.

1
Hello Mendix community: As a comparative Mendix neophyte, I'm struggling to show a subset of calendar events that are associated with a single instance of an entity. For example, suppose I am trying to create an application that allows students to reserve different tools in a machine shop. I would like them to be able to select a tool from a list or datagrid and then see all of the reservations for that one tool to see if there is a time slot available for them to reserve that tool. My domain model has four entities: Tool Groups, which can each have one or more tools. Tool Groups might include "Lathes", "Milling Machines", etc. Tools, which are individual pieces of equipment such as "Bridgeport Mill", "Bridgeport CNC Mill" in the milling machine group. Then I've got students as the third entity. They want to make reservations to use these tools. And Reservations that are made by a student on a single tool with a start date time and an end date time. One student can have multiple reservations and one Tool can have multiple reservations. Here is a link to this stripped-down domain model (at least as I created it): Using a nested data grid, a specific Tool Group can be selected and then a data view listening to that grid shows the Tools in that Tool Group and an individual tool can be selected. That works nicely ... I think. So, I tried to create another data view with a calendar in it that listened to the tool data grid hoping that I could show only the reservations for that selected tool. That didn't work for me. I also can't figure out how to write an appropriate xpath query that limits the displayed reservations to only those for the selected tool but for all students. In other words, I can't figure out how to get either the selected Tool object (or it's name) "into" the calendar as a part of the xpath query. I don't know whether my data model is wrong, that I'm simply a poor writer of xpath queries, I don't know how to select something, or I don't know how to use a listener. If anyone can help me to understand where I've gone off the rails and how to properly go about limiting displayed calendar events to a subset of all calendar events based on a selection, I'd be most appreciative. Thanks, John
asked
3 answers
2

When a calendar day is selected you need to get the start of that calendar day end the end of that calendar day. Take a look at the documentation on how to create those objects. Now you can create a xpath where the Reservation/Start is greater then the beginning of that day but smaller then the end of that day. Then you have all the Reservation objects of that day. This list you can then filter by Student to filter out all the Reservations of a particular student.

You can also filter that first list for a specific tool by filtering it by Tool.

One note though. It is not necesarry to have the Student and Tool duplicated in the Reservation entity. You could use in the xpath the reference. But if you do duplicate, make sure these are synced right with the reference object.

If you need more pointers just ask.

Regards,

Ronald

answered
0

Ronald:

Thanks for taking the time to respond. I've seen enough on the forum to know that you are a frequent contributor and want to start by thanking you and all of the other frequent contributors for helping make this forum such a valuable resource.

I also realize that I have the Student and Tool information duplicated in the Reservation. I fear that is a holdover from working with databases and systems that have independent tables that don't use associations ... and I clearly need to develop more expertise using associations to work effectively in the Mendix framework.

My closest attempt to use an association in the Calendar xpath query to limit the reservations to only those for a single tool looks like:

[MyFirstModule.Reservation_Tool/MyFirstModule.Tool = '[%CurrentObject%]']

Note: The entities that I'm trying to display are MyFirstModule.Reservation objects.

When I run my test application that results in the following stack track that, I think, shows that the CurrentObject is getting selected and loaded properly, but that I've got something wrong with my xpath statement.

I'm hopeful that you or someone will either see what is wrong in my above xpath query or will see what is wrong based on the runtime exception that is thrown:

> com.mendix.core.CoreRuntimeException:
> Exception occurred in action
> '{"amount":-1,"sort":[],"returnsCount":false,"offset":-1,"type":"RetrieveXPathSchemaRawAction","xpath":"//MyFirstModule.Reservation[MyFirstModule.Reservation_Tool/MyFirstModule.Tool
> = '8162774324609325']"}', all database changes executed by this action were
> rolled back
>     at com.mendix.core.actionmanagement.CoreAction.processErrorState(SourceFile:343)
> 
> Caused by:
> com.mendix.connectionbus.ConnectionBusRuntimeException:
> An exception has occurred for the
> following request(s):
>     dc (depth = 0): //MyFirstModule.Reservation[MyFirstModule.Reservation_Tool/MyFirstModule.Tool
> = '8162774324609325']
>     at com.mendix.l.a(SourceFile:59)
> 
> Caused by:
> com.mendix.connectionbus.ConnectionBusRuntimeException:
> 'MyFirstModule.Reservation_Tool' is
> not a valid entity. The meta object is
> based on the last part of the
> following path:
> 'x1MyFirstModule.Reservation /
> MyFirstModule.Reservation_Tool',
> exception occurred on mapping the
> following query: SELECT
> x1MyFirstModule.Reservation.ID FROM
> MyFirstModule.Reservation AS
> x1MyFirstModule.Reservation INNER JOIN
> x1MyFirstModule.Reservation/MyFirstModule.Reservation_Tool
> AS j1myfirstmodule$reservation_tool
> WHERE
> x1MyFirstModule.Reservation/MyFirstModule.Reservation_Tool/MyFirstModule.Tool
> = '8162774324609325', exception occurred on mapping the following
> query: SELECT
> MyFirstModule.Reservation/* FROM
> MyFirstModule.Reservation WHERE
> MyFirstModule.Reservation.ID IN
> (SELECT x1MyFirstModule.Reservation.ID
> FROM MyFirstModule.Reservation AS
> x1MyFirstModule.Reservation INNER JOIN
> x1MyFirstModule.Reservation/MyFirstModule.Reservation_Tool
> AS j1myfirstmodule$reservation_tool
> WHERE
> x1MyFirstModule.Reservation/MyFirstModule.Reservation_Tool/MyFirstModule.Tool
> = '8162774324609325')
>     at com.mendix.cS.v(SourceFile:264)
> 
> Caused by:
> com.mendix.connectionbus.ConnectionBusRuntimeException:
> 'MyFirstModule.Reservation_Tool' is
> not a valid entity. The meta object is
> based on the last part of the
> following path:
> 'x1MyFirstModule.Reservation /
> MyFirstModule.Reservation_Tool',
> exception occurred on mapping the
> following query: SELECT
> x1MyFirstModule.Reservation.ID FROM
> MyFirstModule.Reservation AS
> x1MyFirstModule.Reservation INNER JOIN
> x1MyFirstModule.Reservation/MyFirstModule.Reservation_Tool
> AS j1myfirstmodule$reservation_tool
> WHERE
> x1MyFirstModule.Reservation/MyFirstModule.Reservation_Tool/MyFirstModule.Tool
> = '8162774324609325'
>     at com.mendix.cS.v(SourceFile:264)
> 
> Caused by:
> com.mendix.connectionbus.ConnectionBusRuntimeException:
> 'MyFirstModule.Reservation_Tool' is
> not a valid entity. The meta object is
> based on the last part of the
> following path:
> 'x1MyFirstModule.Reservation /
> MyFirstModule.Reservation_Tool'
>     at com.mendix.cI.e(SourceFile:182)

Thank you for your consideration and support,

John

answered
0

Ronald, Mike, and the Mendix Community:

I wish to report that suggestions from Ronald and Mike were exactly on target and have largely resolved the problems that I had been experiencing. For starters, I was not using relationships properly and, as a result, did not actually have any ReservationTool associations set up. As Ronald suggested (and likely also suspected) I was not managing the duplicate string Item and Student fields in my Reservation entity properly. I have since removed those and am relying solely on what I believe to be more appropriate use of the ReservationTool reference to specify the tool-matching condition for selecting reservations for a single tool. Mike was correct: the xpath filter that works is:

[MyFirstModule.Reservation_Tool = '[%CurrentObject%]']

Now the displayed reservations switch nicely when I select different tools and show only the reservations for that tool in the Calendar. Hooray!

I do have a minor remaining problem: When the application starts up, even though I have "Select first" in my data grids selected, it appears is if the initial rendering of the Calendar takes place before it has an initial CurrentObject because I can an initial error of:

com.mendix.core.CoreRuntimeException: Exception occurred in action '{"amount":-1,"sort":[],"returnsCount":false,"offset":-1,"type":"RetrieveXPathSchemaRawAction","xpath":"//MyFirstModule.Reservation [MyFirstModule.Reservation_Tool = '[%CurrentObject%]']"}', all database changes executed by this action were rolled back

That said, I'm light years ahead of where I was this morning thanks to help and suggestions from Ronald and Mike. Thank you for your help and for helping me to make a start learning how to properly use associations. I can see that developing better understanding and skill in this area will be a key to becoming a more effective Mendix user.

Thanks,

John

answered