A quick question, is there system flag that w...

(Cesar Lillo) #1

A quick question, is there system flag that will let me know if the record is in edit mode? I want to show/disable certain fields if the record is in edit mode. Thanks in advance.

(Grant Stead) #2

If you’re asking to know if some other user is editing the record, then no. If you’re just taking about in the app, then I would say you know it’s in edit mode of the user has a form view open. So turn off show if universally in the UX settings, and then you can use the show if in the column settings

(Steven Coile) #3

As @Grant_Stead indicated, if the user is adding or editing the row, the Form view is used; a non-Form view is used for anything else.

(Steven Coile) #4

There’s no system-provided way to determine how the user is viewing a row. The way I work around it is to maintain a modification counter for each row ([mcount]) that is incremented by the column’s App formula (=([_this] + 1)) every time the row is loaded into a Form view. Knowing that the column’s value is incremented in the (temporary, as-yet-unsaved) Form view, and thus different from the saved, “on-disk” copy, I can compare the form’s copy with the saved copy to determine what the user is doing:

switch((lookup([_thisrow].[KEY], MyTable, KEY, mcount) + 0), 0, “add”, [mcount], “view”, “edit”)

Replace KEY, MyTable, and mcount as appropriate for your schema.

This formula compares the modification counter (mcount) of the visible row ([_thisrow].[KEY]) against the column’s value as stored (lookup(…)). If the row is new, there is no stored copy, so lookup() returns NULL, which I convert to a number (lookup(…) + 0)) (NULL + 0 = 0). If the result is 0, the row is being added (“add”). If the result matches the visible value ([mcount]), the increment from the App formula has not been applied, so I know a Form view is not in use, thus no add or edit is occurring (“view”). Otherwise, knowing that the visible and saved values of [mcount] exist and differ, I assume the App formula has been applied within a Form view to a pre-existing column, indicating an edit operation (“edit”).

Note that [_thisrow] is required within a lookup() to refer to the visible row, rather than to the row targeted by the lookup().

(Steven Coile) #5

So, using the expression in my last comment, you could try to show and hide columns selectively using Show_If. In my experience, that becomes really cumbersome really quick.

My current preference for hiding columns in forms is to layer a Slice atop each and every Table. All of my expressions then reference the slice rather than the table (with a few exceptions). The slice allows me to control what occurs in forms and where, and views allow such control elsewhere.

To hide columns in forms while keeping them available for other views, I add a Show column of the Page_Header category immediately after the last form-visible column, and set Show_If for this Show column to =false. Every column in the slice on this page will be hidden on forms but still available for all other uses.