I will be adding a bit to this story.
Today I had to test something that involved that temporary date. To my stupefaction instead of today's date in the field was Jan 31. The day I had my epiphany and changed the date field for a calculation field.
Obviously, despite being a calculation field, it was not updating.
I tried changing some data from other fields of the table, i put a button on the tab panel to refresh the object trying successively the tab panel, the portal and the field itself. I tried setting the field to itself (not really a change worth updating but who knows), commit record. I tried putting triggers on the tab and on the portal. Nothing got that field to update.
So it is evident that I got the impression in January that I had achieved my goal but was fooled by the auto update that occured when and BECAUSE I changed the field type.
Then while I was looking at the data viewer, I was only getting values for the first row (at the bottom, it is sorted in reverse order, for the purpose of another developer's scripts needs) I remembered (not 100% sure this is actually accurate) that only the first related record (the one in a portal) gets updated when the active record loads or gets updated. Which would explain why i can't get any value for the last record in the data viewer, no matter on which row I click in the portal.
That doesn't explain why the record doesn't updates when I change values of fields in the same portal row...
So anyway, i went to a layout which table is the same as the portal's and tried the button and such other tricks get the record to update. It did not.
I went in the field definition and changed it for @Kirk 's method
Let (
[ var_TriggerTS = z_TriggerTS;
var_status = If (Status = "Closed" or Status = "Complete" or Status = "Cancelled"; "final"; "temporary");
var_chgTemp = Case(
IsEmpty (EndDateTemporary); "yes";
not (IsEmpty (EndDateTemporary)) and var_status = "final"; "no";
not (IsEmpty (EndDateTemporary)) and var_status = "temporary"; "yes"
);
var_false = EndDate;
var_true = If (var_chgTemp = "yes"; Get(CurrentDate); EndDateTemporary)
];
If (IsEmpty (EndDate); var_true; var_false)
)
Of course now it updated. But I might be fooled again because by changing the calculation, it forces recalc of the field for all the records. I will only know it worked if tomorrow when I click on the button that sets z_TriggerTS, the field updates for the specific record I'm on.
It would be best if I could test right away but I have a bout of mental fatigue (or laziness) and can't think of a simple and quick way to overite the value in the calc field, to see if it indeed changes when i trigger the timestamp. (And that is not what i was supposed to waste my time on today to work on today, but it is prerequisite that it works however.)