I am trying to setup a portal in the footer of a list view layout. In the portal it would show records that the user had modified in the past 30 days. I am surprised I have not ran into this issue before but thinking back this is the first time I have tried to do this.
At first I figured this would be really easy to do. I made 2 new global fields in the Main table. One for current user and one for a date 30 days ago. I than made another Main table occurrence tying my modified by and modification date fields two the newly created global fields.
But instead of only showing records created by the user and within the last 30 days it is showing all the records from the Main table. What is the best way to solve this issue?
What Torsten said.... with a couple minor suggested deviations .......
Set the globals for the user account and currentDateMinus30 in the login startup script.
Using this path, you reduce the error potential of forgetting to set this in some script or new layout entry as the fields are ALWAYS set for the current day and user. The only place this would be "brittle" is someone logged in over Midnight, in which case, Torsten's approach would be better.
Not sure if anyone is still watching this thread.
But, my question is why use globals in this case at all?
They could be (explicitly) unstored calc fields in Main:
zc_UserKey, defined as: Get ( AccountName )
zc_DateMin, defined as: Get ( CurrentDate ) - 30
respectively. Relationships work with unstored calls on the LOCAL side of the relationship, which is what you are doing. Then, no need to make sure they get set. They are always live-evaluated when used. But, note that when you include a Get function in a field definition and you want the calc to always display the current result, you need to explicitly set the calculation to "Do not store" in the Storage Options. Otherwise, it will just keep whatever the value was when you created/saved the calc field definition.
I'd say for performance reasons. While very convenient, unstored calc fields come with a high computing cost. Not relevant for short lists, but longer lists will be impacted by longer load times and sluggish scrolling. Global fields do not have that inconvenience.