new record in form

Hey, i’ve created a form which allows a user to enter basic data for creating a new telephone tarrif. This form and the trigger in it do what they should do. Now i want to add a button which clears all the fields and initializes a new record for enetering new data for a new tarrif. But whenever the user presses this button only the old data are shown. I created the new record by using INIT and then CurrForm.UPDATE(FALSE) because i don’t want the new record to be saved immediately. The “DelayedInsert” propertie of the form is set tu “yes”. What do i have to do to show the new (empty) record in the form ? thanks in advance STEFAN

Erm, Stefan, I hate to say it, but using the forum’s search function you would have found the following threads dealing with this subject: By some strange coincidence, one of these threads was started by a certain Stefan Weinreich[:D][:D][:D]

Hey Heinz, i have to say sorry that i didn’t use the search function, espacially for one of the topics was created by me. However both solutions didn’t solve my problem. The problem is that i want to create a new record without beeing saved. There is some code in the OnInsert-Trigger of the tables which prevends records beeing saved where important data are missing. Hence i have put the DelayedInsert-propertie of the the form to “yes”. Unfortunately the new (empty) record isn’t shown in the form, even if i use CurrForm.UPDATE(FALSE). It looks to me as if the form reloads the old record again after it is initialized (and not saved).

Hi I’m not sure but perhaps a Clear(YourRecord) would be helpful in your case. bye André


Originally posted by StefanWeinreich
The problem is that i want to create a new record without beeing saved.

Alright, this changes things a bit. The solutions in the old threads save the new record to the database and do a FIND etc. for the new record afterwards. I’m afraid that what you are trying to achieve is not possible. A simple INIT will clear out and re-initialize the current record and not create a new one. What you really need to do is create a new record “inside the form” only, which is what the system does when you press F3 - you get a new record marked with an asterisk which exists in the form but not in the database (yet). But to my knowledge, there is no such C/AL function, neither in the form nor in the record. How about creating a new record with all the required data initialized to some meaningful default values, so it will be accepted by the OnInsert trigger?


Originally posted by Andre DDB
Hi I’m not sure but perhaps a Clear(YourRecord) would be helpful in your case.

Hi Andre! Just tried it - with the same negative result [:(] The problem is that both CLEAR and INIT only clear out the current record without creating a new one. When the form then updates itself, it still has the notion of the “current record position” and loads the current record again, which is the original one. I checked it in the debugger.

i was off to another project, so i didn’t read your postings in the meantime. I agree with Heinz to create a new record and to save it immediately to the table. This was the easiest way. What it prevends me from doing so is the fact, that i always assume to have DAUs(i don’t know the spezification for that in english. DAU means the most stupid user who is using the application…) using my programs. So i need to make it as save as possible. While the new record is saved there are added some informations like an index, a new phone-number for this service and so on. If the new record is saved immediately after beeing created and the user leaves the form without entering data there would be created a lot (?!) of records without contents. I should have to create a “garbage-collection-application” to delete such unused records, what is not very fine (in my opinion). That’s why i delayed saving the records. No other way to solve this ?

[OFFTOPIC] by Google DAU= Dümmster Anzunehmender User DSU= Dumbest Supposed User (stupidest imaginable user) [/OFFTOPIC] SCNR [:D]

thanks Andre every day is a good day to learn something new… :wink:

Stefan, I’m not really sure if I understand what you are trying to accomplish… You want the user to fill in some required fields before saving the record, right? Then, when the new record is actually saved, you add some more information which is created automatically. So, why don’t you simply add some code into the OnInsert trigger which does a few TESTFIELDs or whatever is required to ensure complete data entry by the user? Ok, this will result in some user education - if they get the 42nd field error, they will know what fields they need to fill in [;)]. You could mark the required fields with some other color, put them on a separate tab of their own etc. If, on the other hand, you want some values already visible in the form when a new record is generated, you could use the InitValue properties or put some code into the form’s OnNewRecord trigger. Together with the NonBlank property, this will make sure these fields have a proper value. Maybe I’m missing something here, but I don’t think your problem is really that complicated… The above are simple, standard techniques. I know, the Navision way is to allow the user to generate records without any fields except for the most important filled in, but here in our system, we are not swamped by huge numbers of almost-empty, meaningless records created by users clicking around just for fun [;)]. Well, maybe your users are different…

Hey Heinz, perhaps i turn around myself and have lost the aim and can’t see the obvious solution. So here’s a little more explanation to my problem: I have created a form where a user can enter the required data for a new tariff, such as price, modelname and modeldescription, phonenumber, special id and some informations about the way the call will be charged to our customer. The call not only can be charged by a simple price (cent per minute), it can be charged as following: first 10 seconds 1 Euro, next 25 seconds 0,01 Euro per second, next 300 seconds free and than 0,5 Euro per minute as long, as the call lasts. You see, it is a little different to create a tariffmodel. So the user needs to enter at least one price, has to allocate it to a customernumber, has to choose a phone number out of a pool and has to decide the way the call will be charged, firstly to our customer (what we will have to pay to our customer) and secondly how it will be charged to the calling person (what we send to the Deutsche Telekom AG and what it has to put to their usual caller-invoice). When the record is saved there are added some more informations such as an index, creating and/or altering date, user-id and it is checked whether the mandatory data are enetered by the user. Now if the user presses “new record” there are entered no initial values, because they can’t be assumed (ie price, max length of call and so on), but when i save the record they are checked and there is always shown an error message because of the missing data. Hence i delayed saving the record to give the user the chance to enter the required data before it is saved. But exactly that’s my problem. Whenever i create a new record with INIT and want to show it at the form (by using CurrForm.UPDATE(FALSE) ) the old record is shown. If i don’t use CurrForm.UPDATE(FALSE) the screen isn’t updated and again the old values are shown. So my problem is: how can i create a new record without saving it but showing the empty fields on the screen. The next step is: it can be that the user has to enter similar tariffs. So he should be able to copy the current data into the new record, but some fields have to be resetted (ie. some flags which mark that there is created or not a new model with this data). I hope i could explain the problem a little bit. It might be that i turn and turn and have lost the simple solution because i think to complicate in the meantime. But i’m sure if so you’ll bring me back to the floor… :slight_smile: thanks in advance STEFAN

Hi Stefan What about an unbound form? Then you can always start with empty fields. The user enters the data, then you can check the data and write it to the record (and clear the fields on the form). bye André

Hey Andre, what is an unbound form ? Currently i’m saving the user-entered data in a table for controlling purposes. Do you mean that i should use single variables instead of a record ? STEFAN



Originally posted by StefanWeinreich
Hey Andre, what is an unbound form ? …

unbound form = form without a table/record in property “SourceTable” And yes, I mean the user only fills the fields on the form (with connected variables). And when he pushs the button ‘Save’ you can test the content of the fields and then write it to your record. bye André

Hi Stefan, What Andre means is a form not tied to a specific table - the fields’ source expressions will be ordinary variables, and upon pressing a “Save” button, you create, fill and save an internal record variable. I think you got the point already. You could use this solution if you did not want your users to use the same form for data entry as well as for lookup/navigation. There will be no forward/backward functionality etc. Well, let me get back to your original form. If I understand correctly: You want the form to display completely empty fields when the user presses F3 (IMHO F3 is just as good as any other “new” button [:D]). The new record shall be saved only when the user switches to another record (DelayedInsert=Yes). Ok, this is standard. You want to calculate some additional values upon OnInsert. Ok, also standard. You want to do some checking of the data upon OnInsert, but, if I get it right, without the form vanishing with an error message (and all the new data with it). Well, this is also standard… Raising a FIELDERROR in OnInsert will not discard the new data. The user can correct his error and try again. So, all that’s left is that you do not want the user to have to press F3 but want to provide some “New”-button instead, right? This brings us back to the original problem which had already been discussed in the earlier thread, i.e. you must save the new record you create internally before you can show it in the form, which in turn causes the OnInsert trigger to throw up a few error messages [xx(] The only solution I can think up at the moment is to do an INSERT(FALSE) on the new record. This will prevent the OnInsert trigger from doing its checks and calculations and allows you to show a new, empty record upon pressing a special button, but will leave you with an empty record in the database, which you want to avoid. Hm, how about putting some code into OnCloseForm, which checks if the user has modified the newly created record? If the user did not do any modifications, the new record is deleted again?

If you follow my suggestion to delete the empty records upon the form closing, I’d recommend using a new table field “Record valid” (Boolean) or the like, which is set upon the user modifying the record. You can then prevent other users or programs from using or seeing these not-yet-complete records. Of course, the checks etc. need to be moved from OnInsert to OnModify… [;)]

Oh, the copy function you mentioned should come easy. This actually requires nothing but popping up the table’s lookup form, having the user select a record and create a new record internally, based on the selected record. Fields may be modified or cleared as desired. The new record is then saved to the database and shown in the form. We have several forms where direct copy/paste is not allowed, but where this functionality is instead provided by some lines of code.

Hey Heinz, your suggestions regarding doing no checks in OnInsert and using OnCloseForm to delete unnecessary records looks good to me. I guess i’l try the way you recommended. That’s what i meant with “turn and turn and loose the aim”… :wink: btw: i’ve never used function FIELDERROR before. So i took a look at the online help… but it was not really helpful to me. What is the difference between FIELDERROR and ERROR ? And where’s the benefit of using FIELDERROR ? As far as i could read FIELDEEROR causes the trigger to be stopped (as ERROR does) and shows an individual message (as ERROR does) ?!.. thanks so far STEFAN

Stefan, the difference is that ERROR can be used to throw any error you need, while FIELDERROR checks the field’s value against the value you provide, then displays an error message containing the field’s name and a message that some value is required or not allowed. It’s really just a shorthand for IF "xxx" <> reqVal THEN error('%1 must be %2', FIELDNAME("xxx"), reqVal); or IF "xxx" = 0 OR '' THEN // yeah, illegal comparison, I know ;-) error('%1 must not be empty', FIELDNAME("xxx")); Good luck - let me know if things work out the way you want [8D]

Sorry, mixed it up with TESTFIELD, but it’s the same principle [;)]. You don’t need to use FIELDNAME to construct some error message, this is done for you automatically. Of course, in your triggers you should use TESTFIELD instead of FIELDERROR for simple data checks. I mixed that up, sorry.