I am trying to create an event log. I want to capture in this event log every time a new company record is added. I also want to capture the name of the new company.
I coded an action on a button to create " A new company. " I then thought I would use the OnRecordSave event to check if the relevant information had been completed in the new record before saving it out to the event log. If there is no relevant data entered, the record is deleted and not added to the log.
However, the OnRecordSave tries to execute the moment I try and enter the name of the new company and therefore immediately deletes the record.
Has anybody got any ideas on how I get round this. I am new to Servoy and programming and am sort of hacking around trying to find how it all works!!
The code I’ve so far got for the OnRecordSave event, is below.
controller.setSelectedIndex(globals.gCountRecords);//looks at how many records have been created
application.output(globals.gCountRecords);
var companyName = name;
var companyID = companyid;
application.output(name);
if (companyName != null)//If company name is not blank then creates a log in the event table.
{forms.eventList.controller.newRecord();
forms.eventList.controller.setDataProviderValue(‘eventdescription’, “A new company has been added called:”+ companyName) ;
var userName = security.getUserName();
forms.eventList.controller.setDataProviderValue(‘username’, userName);
forms.eventList.controller.setDataProviderValue(‘companyid’, companyID);
forms.eventList.controller.setDataProviderValue(‘eventttype’, ‘Company created’);
forms.eventList.controller.loadRecords();
application.output(userName);
}
//company name has been left blank, so record is deleted and not saved.
application.output(“blank record”)
//Delete current record
controller.deleteRecord();
globals.gCountRecords = globals.gCountRecords - 1;
Maybe it’s easier to use the logging that’s already built inside Servoy.
open developer and press F1 for help.
Search for “tracking”.
Possibilities
-Build a form on the logging table together with some filters(create, delete, fieldname, etc..) in order to analyse things.
-Show logging history on record level
etc…
Warning, MerMer, I’m a “relatively newbie” too when it comes to Servoy methods. I hope if this is not accurate someone will correct me! here goes …
But I think what you’re looking for is:
application.setFocusLostSaveEnabled(false)
Use this in your “a new company” method to prevent Servoy from attempting to save the record until it is explicitly told to do so. Provide a “Save” button that runs all validations, creates your log entry. When you’re finally ready to leave the “new record mode”, look at the controller.saveData() function to finally save (“exit”) the record.
There is nothing wrong with the syntax you use, but there are what I would consider simpler alternatives. I’m wondering if there are benefits to using the setDataProviderValue function that I’m not aware of?
Many thanks for all the posts - alot to think about.
Rich, its great that Servoy has so many ways to do the same thing - but for a newbie like me it’s also confusing.
I don’t really appreciate the differences between using one function and another and it would great if the documentation was more explicit about when you should use each one versus another. I am sure that it would help users like me to get up to speed more quickly and write more efficient methods. Right now I find myself stumbling around trying different things to see what works - when it does I stick with it - which is probably creating bad habits for how I handle other stuff in the future.
I know exactly what you are saying about learning Servoy. If you come from a FileMaker background it really is a very different way of thinking. It is more of a programming type environment than a scripting type of environment (although it is JavaScript). The good news is that there generally are multiple ways to do something. The bad news is when learning it is hard to know which is better, or if there is a difference at all.
Once Servoy starts to click you will see how powerful it really is. Of course that power does comes at the cost of more complexity. But one reason I’ve have always been a big fan of FileMaker (and continue to be a big fan) is that it provides a great ratio of power versus complexity. I find the same thing in Servoy.
The difference I believe is their target markets. Servoy requires the use of a backend database (Servoy is not a database, but rather a presentation tool for a backend database). That is not trivial, and can be very complex. That is why large companies have teams of DBA types to keep their data farms running properly. So users of Servoy really must have more sophisticated technical infrastructures in place. FileMaker is both database and presentation tool. For less demanding applications that is a very appealing combination. It is all about using the right tool for the right job.
The way I look at it… FileMaker is the high end of the low end… Servoy is the low end of the high end.
Playing in the high end space does generate more complexity with a reward of more power.