Help with detailed logging

I am hoping someone can offer some ideas for how to implement detailed logging of what data was viewed in a grid.

I need to track which records users have viewed. So far all I have been able to come up with is to insert the record ID into a log during the onRecord event. However when loading a grid with 50 rows I don’t want to make 50 SQL inserts.

I have tried appending the record ID to a session variable in the onRecord event which would allow me to make the SQL insert using the onFooter event. When that event fires all of the record IDs have been appended into a single variable: So for example a grid with 4 rows: Record IDs 1,2,3 and 4.

onRecord: [session_IDs] = [session_IDs] . {RecordID} . ‘,’;

in the onFooter event I can reference [session_IDs] which will be “1,2,3,4,”

I can then remove the last character from the variable and insert “records viewed = 1,2,3,4” into a log table.

However I also want to log when a user clicks the detail button to look at an individual record. The only events that seem to be firing when the detail page loads are onScriptInit and ‘onRecord’. That doesn’t really help me as they are the same events as the main grid, and I don’t want to make a SQL call on each and every onRecord when viewing the main grid. But the header/footer events don’t fire on the detail page so I can’t call the SQL insert from those events when viewing details.

Is there some way to identify whether the current page is the main grid or the detail page during either the onScriptInit or onRecord? If I could check that then I could run the SQL insert from one of those events only when the detail page loads and from the onFooter event for the main grid.

Replying to my own post with a solution in case anyone else comes across this later with the same need:

Since the onHeader fires for the main grid and not for the detail page I can set a variable in the onHeader which can be checked in the onRecord. If the variable has been set by the onHeader then it is the main grid.

onScriptInit:

[glo_page_has_header] = 0; //reset the variable on init

onHeader:

[glo_page_has_header] = 1; //set the variable to 1, only occurs on main grid

onRecord:

if ([glo_page_has_header] == 1)
{
//this is the main grid, concatenate the recordID on each onRecord event. Logging will occur in onFooter event
[session_IDs] = [session_IDs] . {RecordID} . ',';
}
else
//this is the detail page, make a log entry
{
//put SQL insert here. Insert just {recordID} for this single detail record.
}

onFooter:

//put SQL insert here... insert [session_IDs] which contains the concatenated list of all records in the grid.