How to add new record in a simple table?

Hi, I am newbie and want to know what code should be there for new record insertion? I want to put code in Code unit and dont want to set any code in table. With Best Regards, Naimish Dave

CLEAR(recMyRecord); // this clears and initializes all fields in the record (you can also use recMyRecord.INIT; this doesn’t clear/initializes the primary key fields) recMyRecord.VALIDATE(“key Field 1”,“Some Value”); recMyRecord.VALIDATE(“key Field 2”,“Some Value”); … recMyRecord.VALIDATE(“Field 1”,“Some Value”); recMyRecord.VALIDATE(“Field 2”,“Some Value”); VALIDATE triggers the code of the “OnValidate”-trigger of the field. If you don’t want this, use recMyRecord.“Field 1” := “Some Value”; recMyRecord.INSERT(TRUE); // true triggers the “OnInsert”-trigger of the table. If you don’t want this, use FALSE. I hope this helps you starting in Navision. Good Luck!

Hi, Thanks I will try it and will revert back if any problem. With Best Regards, Naimish Dave

Hi,

quote:

CLEAR(recMyRecord); // this clears and initializes all fields in the record (you can also use recMyRecord.INIT; this doesn’t clear/initializes the primary key fields) recMyRecord.VALIDATE(“key Field 1”,“Some Value”); recMyRecord.VALIDATE(“key Field 2”,“Some Value”); … recMyRecord.VALIDATE(“Field 1”,“Some Value”); recMyRecord.VALIDATE(“Field 2”,“Some Value”); VALIDATE triggers the code of the “OnValidate”-trigger of the field. If you don’t want this, use recMyRecord.“Field 1” := “Some Value”; recMyRecord.INSERT(TRUE); // true triggers the “OnInsert”-trigger of the table. If you don’t want this, use FALSE.

I want to know that how to insert record in more than one table tables, in my case I have created a card for job timesheet and insertin record in it, now here I want to add same record in other table also so what should be code for it as I dont how to add record in table whci h fields are not avialable on card. With Best Regards, Naimish Dave

quote:

now here I want to add same record in other table also so what should be code for it as I dont how to add record in table whci h fields are not avialable on card.

It is not completely clear to me what you wanted to say, but I’ll try anyway. To add this record to another table: recNewTable.TRANSFERFIELDS(recOldTable); But for doing this, there are some prerequisites: if a field number in both table exists, the field must be the same name and type in both tables, otherwise you will receive an error. If this is not the case, you have to transfer the fields 1 by 1. I hope this answers your question.

Namish I have been developing Navision for 10 years now, when I started this forum was email based, the way I learned my skills was by lookin at the codeunits in Navision, and trying to understand them, there are many examples of how to Insert and Modify records. Lets look at posting codeunit 80 this is large but if you can understand how it works, you will have a better understanding. It checks to see if the records are filled out properly, headers and lines. It filters the lines and checks to see if there is anything to post. It creates and Transfers some of the Sales Header fields to Sales Shipment Header, then it does the same with the lines. inserts the shipping quantities on the shipment lines. It creates a Item Journal Line and posts this to create the Item Ledger entries. If you are part shipping it then updates the sales lines with the shipped quantity etc: So my advice, print it out and read the code, spend time understanding it, don’t think you could do it better, look at the way they name the variables, and how easy this makes identifying the records, then adapt thier naming conventions in your code. Then your “Timesheet Header” variable will become TimesheetHeader TRANSFERFIELDS transfers fields with the same number and type between the 2 records, look at the Sales Line and Sales Shipment Line tables and how many fields have the same number and Type, the values in these are transfered in the codeunit 80, then additional fields are filled in. Hope this helps, and welcome to Navision Development.

Hi, Thanks to you all for your answers, Let me get more precise. I have created one table with following structure (named Timesheet): Enabled Field No. Field Name Data Type Length Yes 1 Instruction Text 50 Yes 2 Name Text 50 Yes 3 Description Text 50 Yes 4 Work Description Text 50 Yes 5 Mon Integer Yes 6 Tue Integer Yes 7 Wed Integer Yes 8 Thu Integer Yes 9 Fri Integer Yes 10 Sat Integer Yes 11 Sun Integer Upto here it is Ok and I am able to create new web part as a entry form for above table and I am able to Insert and Save data in it. Now parallely I want to insert data in JOB JOURNAL LINE table too. For one TIMESHEET record I want to enter 7 records in JOB JOURNAL LINE (i.e. Mon to Sun). Here you can see that both table doesnot have identical structure so I think I cannot use TRANSFERFIELDS. This is my problem, how to insert data in another table who dont have same structure? With Best Regards, Naimish Dave

Add some code into the OnInsert Trigger of the Timsheet table: FOR I:= 1 TO 7 DO BEGIN JobJournalLine.INIT; // initialize the fields JobJournalLine.INSERT(); END; whereby I is an integer type variable and JobJournalLine is a record type variable with the sub type of “Job Journal Line”.

Naimish, I really think you are going about this the wrong way. Could you please give alittle more detail about WHAT you are trying to achive (rather than HOW you are plannign to achive it). The Mon Tue Wed fields, why are they integer? Are they refering to hours worked or some thing similar? Why are you seperating the days into differnt fields? This is going to keep causeing you problems down the line. I think you need a structure that will be date and then the quatnity. Please post more information, and I will try to help you further.