CMDBuild Forum

Fetch Data from other Class

Hi I am trying to copy data from one class to another class with a database trigger.
I have two classes “myRoom” & “myAlarm” and copying data from “myRoom” to “myAlarm”.
Created a reference field in “myAlarm” with domain “Room_Alarm” And then initiated the following trigger on “myAlarm”. Query returned successfuly but when I attempt to insert a new card, an error pops up - ERROR: record new has no field “myRoom”

Could you please point out I am mistaken ? Thanks in advance

TRIGGER FUNCTION

CREATE OR REPLACE FUNCTION Alarmtest()
RETURNS trigger
LANGUAGE ‘plpgsql’

AS $BODY$
DECLARE

code varchar;

BEGIN

SELECT "Code" FROM "myRoom" WHERE "Id" = NEW."myRoom"      

INTO code;

NEW."Code"	 = code;

RETURN NEW;

END;
$BODY$;

CREATE TRIGGER alarmtesting
BEFORE INSERT
FOR EACH ROW ON “myAlarm”
EXECUTE PROCEDURE Alarmtest();

ERROR Message:

image