CMDBuild Forum

Code needed only in bulk upload

We are experiencing with cards that have not the value in field Code.
Bulk upload needs valorization field Code, while data entry in GUI doesn’t require code, so the data is not entered.
Export data fails for record that have code NULL.
Anybody experienced this trouble? Have we to add a trigger for valorization? How can we find all classes that have this trouble?
Thanks in advance

1 Like

Hello Samuela, we too have customized some classes by hiding the “Code” field.
In order to avoid errors during the import/export we added some triggers to add a value to the code field. I’m pasting an example at the end of this post.
If you want to find all the classes with the “Code” field hidden, take a backup of your database then search the output for the string “MODE: hidden”: you’ll find all the columns that are hidden the GUI.

Hope this helps!

CREATE OR REPLACE FUNCTION public.tt_gdprasset_code()
    RETURNS trigger
    LANGUAGE 'plpgsql'
    COST 100
    VOLATILE NOT LEAKPROOF
AS $BODY$
DECLARE
   corporategroupCode VARCHAR;
   seqname VARCHAR;
   newCode VARCHAR;
BEGIN
    SELECT "Code" INTO corporategroupCode FROM "CorporateGroup" WHERE "Id" = NEW."IdObj2" AND "Status" = 'A';
    seqname := 'corporategroup_' || lower(corporategroupCode) || '_seq';
    newCode := upper(corporategroupCode) || '.' || to_char(nextval(seqname), 'FM00000');
    UPDATE "GDPR_Asset"
	SET "Code" = newCode
    WHERE "Id" = NEW."IdObj1"
    AND "Status" = 'A';
	RETURN NEW;
END;
$BODY$;
1 Like