Code Auto-increment

Hi!

I’m new to CMDBuild.
I’m trying to figure out how to auto increment the Code assignment for each card.

By adding new card the code will automate its code assignment by increment of 1 from previous card entry

I have one idea, but maybe not 100% correct.

1.- Make Code Readonly
2.- Make Code hide in create mode. (not for Update or read)

  • Code Visibility:
    if (api.mode == "create"){ return false; }
    3.- Make a Trigger in Database for Code Autoincrement. Tablename in Database are normaly like Classname
    CREATE SEQUENCE YourSequence;

CREATE OR REPLACE FUNCTION YourSequenceFuncion()
RETURNS "trigger" AS
$BODY$
BEGIN
New.Code:=nextval('YourSequence');
Return NEW;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;

CREATE TRIGGER YourSequenceTrigger
BEFORE INSERT
ON YourTable
FOR EACH ROW
EXECUTE PROCEDURE YourSequenceFuncion();