How to only allow users to edit new records

For a phone log, what is a good way to only allow users to edit new records?

I had an issue with editing records in a portal, because I needed run a method onDataChange to disable visability of a specific field in the row.

What I did was to create a hidden tab panel to display just the one record that was selected in the new form.

So if the record is new, then the hidden tab panel or FID opens to allow editing.

Not sure if there is a easier method, or even if thats what you are trying to accomplish, but it works for me.

Erich

just a quick suggestion… you can use the readOnly property associated to the form. I play quite often with that… put it on false when adding a new record… set it to true when browsing the old records…

automazione:
just a quick suggestion… you can use the readOnly property associated to the form. I play quite often with that… put it on false when adding a new record… set it to true when browsing the old records…

Interesting. How can I set the readOnly property associated with a form? Have you tried it with webclient?

Hi,

It is also possible to do this kind of thing at the database level:

I use a numeric field called document_locked to keep invoices locked
document_locked == 0, editable
document_locked == 1, locked
document_locked == 2, to unlock locked records :slight_smile:

Then I have a trigger function the PostgreSQL database

CREATE TRIGGER trg_acc_documents_lock_check
  BEFORE UPDATE OR DELETE
  ON acc_documents
  FOR EACH ROW
  EXECUTE PROCEDURE acc_document_lock_check();

calling

CREATE OR REPLACE FUNCTION acc_document_lock_check()
  RETURNS "trigger" AS
$BODY$
BEGIN
    IF TG_OP = $UPDATE$ THEN
    	IF NEW.document_locked = 2 THEN
    		NEW.document_locked:= NULL;
            RETURN new;
    	ELSEIF OLD.document_locked = 1 THEN
    		RAISE EXCEPTION $Cannot update a locked document number %$,OLD.document_number;
    	ELSE
    		RETURN new;
        END IF;
	END IF;
    IF TG_OP = $DELETE$ THEN
    	IF OLD.document_locked = 1 THEN
    		RAISE EXCEPTION $Cannot delete a locked document number %$,OLD.document_number;
    	ELSE
    		RETURN old;
        END IF;
	END IF;
END
$BODY$
  LANGUAGE 'plpgsql' VOLATILE;

Westy:
Interesting. How can I set the readOnly property associated with a form?

controller.readOnly = true;

Westy:
Have you tried it with webclient?

just try it… but problably it does not yet work

You can also use the Servoy Security system where you can exclude/include groups on editing, visibility etc. On a form/element level.

Really fantastic!!!