Presuming KlantContact is the contact table so why are you trying to get the last record on the whole table? By the look of the FINDLAST code you are assigning the contact number as the same as the last number in the table.
But … using the number series functionality the code could just simply come down to:
IF Customer.“Digital shipment” = TRUE THEN BEGIN
// Empty primary key field
Contact.Type = Contact.Type::Person;
Contact.Name := ‘Crediteuren administratie’;
// shouldn’t this be inherited from the Cutomer record?
// where does this “Contact No.” come from?
INSERT(TRUE) will fire the OnInsert trigger on the Contact table before inserting the record in the database as the primary key “No.” field is empty and will assign a unique value to “No.” allowing the record to be inserted into the database without a primary key violation (i.e. trying to insert a record with a same primary key value that a record in the database already has)
Still do not exactly know the context of this code and what you want to achieve with it; for example why do you check IF Customer.“Digital shipment” = TRUE THEN BEGIN?
Instead of IF Customer.“Digital shipment” = TRUE THEN best practice is to write IF Customer.“Digital shipment” THEN
Might even call VALIDATE for the Name field to ensure the code in the OnValidate trigger of this field it being executed:
This also brings makes me wonder why you assign a hard coded value to Name, but probably this is just an easy way to get data in that field for the sake of your example
As you can see, Niels, there is a lot to your code example to be said and, not knowing the context and exact goal, I took the risk of stepping in and to try to make something, more NAV like, out of it.
Rereading your first line (I … want to get the last record of a table) the most straight forward answer would have been (to get the last record):
But apparently, seeing a lot more code, you are wanting more. So for next time try to be somewhat more specific on what you want to achieve.
and an extra contact with the name: Crediteuren administratie is added. But the problem is now that the new contact with the name Crediteuren administratie has primary key: 9913. But the ‘normal’ contact has primary key: 46069. So it will be nice ofcourse to have the contact name Crediteuren administratie 46070. So that 's what I mean with Last contact + 1. But how to archive that? Thank you.
Still no answer to my last question, Niels. Sorry to insist, but this way we are heading nowhere. So let me repeat it: How do you know “Crediteuren administratie” is not in the database?
And BTW, I am Dutch and can read the Dutch error messages, but in general your fellows out here are not Dutch, so run your application in ENU so you get ENU messages which you can past in your posts here.
I can see bij Verkopers that a new record is made. So there I can see if the record is Crediteuren administratie" added or not. And I can also look in the table contact if the record is added. But so my question is how to make the new record with a increment number. So if my last record is for example: 4006, so Crediteuren administratie has to have primary key: 4007. Thank you.
Congrats and of course keep on trying. However, do you want to create every time a new contact with Name “Crediteuren administratie”. You still do not seem to check (at least not with this code) whether it already exists or not?