I need to implement a record that adds to the list of records, like a comment area. When someone adds a new record, it should be appended to a list instead of editing the one record. Expanding on my comment analogy, it would be hidden in table view but detail view would have the list of comments with an text area and "Add new comment" button. When the record is added, it would need to show the username of who added it and the timestamp.
I've tried adding a new table and calling that from the tablename_init hook but I'm not able to add to a list of records, just edit the record once it's been created. Can anyone help me figure out how to make this work?
Appending records instead of editing
Re: Appending records instead of editing
This should be possible. Sounds like you are describing a parent/child relationship. Parent would be the initial tableview and child records are the comments which live in a different table. See if that will work for you. Best of luck.
Re: Appending records instead of editing
I figured how to make this work and wanted to document it if anyone needs to do this. KSan was correct, I just had to work it out.
I needed to have comments available for workorders that describe the type of work done, reasons for delays, etc.
I created the workorders table with several fields. I decided good keys to connect comments to workorders would be address and dateOfService. I created another table called workorderComments with 2 fields(besides PK ID): comments and workorderID. I made the comment field a text area. The workorderID field was made a lookup field with workorder.address as the Parent Caption Field part 1, <space>-<space> as separator, and workorder.dateOfService as part 2.
In the workorders table properties, I made sure it was displaying child records from comments, went into Parent/Child settings and made sure Enabled was set to yes. Make sure "Display detail view in a separate page" is checked.
Now when accessing specific workorders, there is a table below the workorder called Comments with an Add button. I can add comments and they are only shown in the detail view for the workorders I'm looking at.
I needed to have comments available for workorders that describe the type of work done, reasons for delays, etc.
I created the workorders table with several fields. I decided good keys to connect comments to workorders would be address and dateOfService. I created another table called workorderComments with 2 fields(besides PK ID): comments and workorderID. I made the comment field a text area. The workorderID field was made a lookup field with workorder.address as the Parent Caption Field part 1, <space>-<space> as separator, and workorder.dateOfService as part 2.
In the workorders table properties, I made sure it was displaying child records from comments, went into Parent/Child settings and made sure Enabled was set to yes. Make sure "Display detail view in a separate page" is checked.
Now when accessing specific workorders, there is a table below the workorder called Comments with an Add button. I can add comments and they are only shown in the detail view for the workorders I'm looking at.
Re: Appending records instead of editing
Great work!!! Thanks for sharing your solution.
Re: Appending records instead of editing
Very cool. Thanks! From document control perspective this is so superior than just including a comments field in a report. Add in the username and then you have a record of who made each comment. Powerful.
Re: Appending records instead of editing
Yes, I forgot to add that I also created a read-only text field defaulting to "created by Username" as well as "created date and time" that were both hidden in detail view. This automatically shows who the comment was created by and when.
I'm glad that this could help you, Dave!
I'm glad that this could help you, Dave!
Re: Appending records instead of editing
The only downside is that it doesn't seem to work on a mobile device when I used 5.20.

It might be the way I'm doing it. There are of course two ways to do it ... one is where a popup window appears keeping the detail view of the parent record grayed out in back (which is what I'm doing now), and the other is where you click a link that takes you to an entirely new page where the comments could be added ... I suspect this second option still works.
I'd also love to have a counter when you look at the detail view of the parent record that shows at the top of that view how many comments there are. Even better if you could see that as a column in the table view of all the main records.
Also it would be great if the table view of the comments (not the detail view) would force you to only view those comments associated with the parent record. Currently, after you create a comment it puts you in the table view of the comments where you can change the key field to view other comments which can be confusing if you don't know what you're doing.
Do you know how to do that? I need to figure it out ... if I do I'll let you know.

It might be the way I'm doing it. There are of course two ways to do it ... one is where a popup window appears keeping the detail view of the parent record grayed out in back (which is what I'm doing now), and the other is where you click a link that takes you to an entirely new page where the comments could be added ... I suspect this second option still works.
I'd also love to have a counter when you look at the detail view of the parent record that shows at the top of that view how many comments there are. Even better if you could see that as a column in the table view of all the main records.
Also it would be great if the table view of the comments (not the detail view) would force you to only view those comments associated with the parent record. Currently, after you create a comment it puts you in the table view of the comments where you can change the key field to view other comments which can be confusing if you don't know what you're doing.
Do you know how to do that? I need to figure it out ... if I do I'll let you know.
Re: Appending records instead of editing
Sorry to see this just now, davea0511. I have no problem with the popup on mobile with 5.22 except for photo upload. I'm using Firefox for Android. When I try to upload a photo, the Save New button simply doesn't work though text-only works as expected. Luckily I don't need much mobile support for the time being.
As for the counter, I would think it could be done with one of the "calculating/counting fields" how-tos. You'd probably have to use the tablename_init hook to calculate the value then make some changes to the tablename_templateDV.html (in /templates) to add the result of the init snippet to the top of the table. Maybe add another row of empty cells except for the one where the count should reside? Same goes for table view, really, except for the template would be tablename_templateTV.html.
I don't allow the table view of comments, because they have no meaning without being tied to the parent record. Mine does go to the comment DV after insert but I just tell my people to close it or click outside the window, which closes to the parent. I'd like it to go back to the parent record but I haven't figured out how yet.
As for the counter, I would think it could be done with one of the "calculating/counting fields" how-tos. You'd probably have to use the tablename_init hook to calculate the value then make some changes to the tablename_templateDV.html (in /templates) to add the result of the init snippet to the top of the table. Maybe add another row of empty cells except for the one where the count should reside? Same goes for table view, really, except for the template would be tablename_templateTV.html.
I don't allow the table view of comments, because they have no meaning without being tied to the parent record. Mine does go to the comment DV after insert but I just tell my people to close it or click outside the window, which closes to the parent. I'd like it to go back to the parent record but I haven't figured out how yet.
Re: Appending records instead of editing
Just to clarify above - when I said "Maybe add another row of empty cells..." I was meaning in TV, not the DV template.