In the dispatcher mashup
demo on Greenhouse
, we use this feature for a slightly different purpose, which is to help segregate user input and actions so multiple users can use the demo without login problems. This article provides the details of how the dispatcher mashup demo accomplished this goal.
The dispatcher mashup is a demo that allows the login user to assign service orders to drivers and vans. Users, acting as dispatchers, use the ActionForm widget to assign an order to a driver. The assignment is saved in a database table. Here is an example of the DDL statement we used to create the table:
create table dispatcher.assignment (
orderid int not null,
truckid int not null,
constraint fkey_order FOREIGN KEY (orderid) REFERENCES dispatcher.serviceorder,
constraint fkey_van FOREIGN KEY (truckid) REFERENCES dispatcher.vans
Notice how orderid and truckid (same as driverid) are associated. Also notice the extra column for the user ID (userid). The goal is to save the user ID of the login user who is using the demo into the database table together with his or her assignments. This way, we can separate assignments completed by one user from assignments completed by a second user and avoid conflicts.
Now, to continue with how users complete the assignments. The ActionForm widget is configured to run a relational feed that was created using an insert statement, for example:
insert into dispatcher.assignment (userid, orderid, truckid) values ( ':MHUBLOGIN', ':orderid', ':driverid' )
You can insert parameters into an SQL statement by prefixing parameter names with ':'. In the example above, we defined three string parameters, indicated by the single quotes around each of the parameters, in the values clause. Notice that the first parameter uses the built-in parameter MHUBLOGIN. The parameter does not get its value from the generated URL, but instead gets filled in by the runtime logic with the authenticated login ID. Using the insert relational feed above, assignments are stored with the user login ID automatically, and data is pulled based on this login ID.