I’m currently working on a small functionality to make it possible to manage what fields are editable and what fields are not editable based on data in another table.
Extract from the code:
iss_FormSetup.GetField(‘MyFIELD’,“Record Type”);
IF CurrForm.“MyFIELD”.EDITABLE AND (NOT FormFieldSetup.IsEditable) THEN
CurrForm.“MyFIELD”.EDITABLE(FALSE);
The code piece is called from the form OnAfterGetRecord and again if the value in “Record Type” is changed. It works fine when the form is opened, as “MyField” is visible. But if the “Record Type” tells me that the field should be Not Editable, then when I change back the “Record Type” value, to a value which should be Editable, then it’s still not “Editable”. A quick look at the code of cause tells you why: It’s checking the CurrForm.MyField.EDITABLE value, which has just been FALSE.
If I removed this code, then it would work, but since we here talk about some generic I’m using in many tables, then it’s not so good, I would have to change this a lot of different places.
So what I’m looking for is really a way to look up the Initial value of the Editable property of the field? Is this possible?
Thanks, why didn’t I think about this myself? [;)] Maybe because my programming is getting a bit rusty - actually coding is not what I do the most these days. Mostly I just take on a few development tasks for the fun of it, and to make sure I don’t forget it…
But do you have a suggestion how to work with forms in a more generic fashion? In example with tables it’s very easy to list the fields in the table, but it’s not quite that easy to get a list of active controls in a form. Or is there?
A long time ago there was version 2.01. For that version (and it also works for more recent versions) I created an advanced security system with roles that are added to other roles, field security, record security, logging.
To (partly) automatically do field security for a form, I had to export it as text. I had a function to import it into some tables to know which fields exist on the form and that could be secured. I also had a function to export the code to be put in the OnOpenForm-trigger (a function-call for each field). In the function I returned a value that decided that the field was visible+editable or visible+not editable or not visible.
So in short, you should create a table in which you put the form ID and the names of the fields. Another table in which you define the role (or the user) + the form ID + the name of the field + a field to define the security on it.
In the OnOpenForm, you call a function with the userID, the form ID, the name of the field (FIELDNAME(“The Field”) or ‘Some Name’ if the field is NOT a field of the sourcetable) and the return-value says what security you need to put on it.