Integrated Application Platform › Forums › General › Using Triggers
- This topic has 5 replies, 2 voices, and was last updated 5 years, 11 months ago by
ajith.
-
AuthorPosts
-
October 13, 2017 at 3:05 am #1336
ajith
ParticipantHi,
I am trying to use Triggers for the first time.
I have a table named hmEmployees for which I have defined a trigger by naming an item in the same library as Trigger_hmEmployees . I wanted the trigger to insert part of the info from the table into another table, which was not working. So, I changed the code to
function(transaction, oldrecord, newrecord) { Inspect(newrecord) }
Whether I output a new record, delete a record or modify an existing record in the table hmEmployees through an Access, the Inspect(newrecord) doesn’t get called.
What is it that I am doing wrong?
Thanks,
ajithOctober 13, 2017 at 8:44 am #1337j_ferguson
ModeratorHi Ajith,
I tried the same thing on my copy and it worked even when I was using AccessControl to insert records. My table is a very simple table and I am running suneido.exe standalone.
If you are running client-server, the trigger will be executing on the server side and the Inspect will not work as expected. In that case you could try using SuneidoLog, or writing to a file instead to debug your trigger.
If you are running Suneido standalone, it is possible there is something about your table that is different from the simple one that I set up. Again, writing to a file (you can use the AddFile function for that), or SuneidoLog would be a better option for debugging than using Inspect in your trigger.
I hope this helps you figure it out. If not, with a little more information we should be able to sort it out.
October 13, 2017 at 8:53 am #1338j_ferguson
ModeratorI also forgot to mention that if you are running client-server and you modify a trigger function, you may have to unload that trigger code on the server so that it re-loads your new code:
ServerEval(‘Unload’, ‘Trigger_tmEmployees’)
Or, you can use a brute-force method of restarting the Suneido server, that works too.
October 13, 2017 at 9:33 pm #1339ajith
ParticipantHi Jeff,
Thanks to your reply. Great to hear from you after a long time.
I deleted my table and re-created it and the trigger is getting called. But, it is not working as expected, instead it is giving an error. I will look into that error and get back if I need your help.
I noticed that the trigger doesn’t get called if the the library entry for the trigger is made after the table is constructed. I checked it twice by deleting the table and re-creating it and got the same pattern. I am running Suneido as standalone. My table has a details table linked to it and has two keys, one of which is a compound key from three columns.
Thanks,
ajithOctober 16, 2017 at 9:19 am #1340j_ferguson
ModeratorHi Ajith,
It shouldn’t matter when the trigger definition is created. I wonder if there is an error or exception happening that you are not noticing? If this continues to be a problem, you might consider attaching an export of your trigger definition as well a dump of the table the trigger is on.
Thanks.
October 17, 2017 at 9:28 pm #1341ajith
ParticipantHi Jeff,
Thanks for your reply. May be I missed some error as you say. Except for the initial trouble I had which was solved by re-defining the table, it is working as I wanted.
Thanks,
ajith -
AuthorPosts
- You must be logged in to reply to this topic.