I am first time programer for Navision and need some guidence
I have two tables in the Navision Sql database one is navisions own table and the other one is a new table created by me. Now on a scheduled time every day I want to transfer rows from my new table to navisions table and delete rows in my table after the transfer is complete.
can some one give me a sample codeunit example to carry out this job
Thanks
Kumar
0
Comments
May be this could help...
Make a new codeunit (you might need a SingleInstance codeunit - read about them in Navision programmer's guides).
Try to declare an Automation variable there for Navision Timer 1.0 (dll) - it is included into a standart Navision installation. In its properties define that it goes "WithEvents". Now you can code on the event triggers.
You may set the time interval when the event trigger should be called when you start this codeunit for example.
Dmitry
The Navision way:
You need to create a Navision table to match the SQL table and set the LinkedObject property to Yes. This wont actually create a table in SQL but will allow Navision to use it as a regular table. So you can write code like this - sorry cant remember exact function syntax:
You would have to schedule this with a timer or use NAS.
The SQL Way:
Make a sheduled SQL job and run a simple script:
This posting is provided "AS IS" with no warranties, and confers no rights.
If RecTo table has lot more fields than RecFrom table and I want to map spaecific fields for example
RecTo has fields A,B,C,D,E,F
and
RecFrom has fields X,Y,Z only
and I want to map A to X,C to Y and E to Z. Of course their respective field types are same.
then how does the code in the Navision way will look like?
Thanks and best regards
Kumar
RecTo.C := RecFrom.Y;
RecTo.E := RecFrom.Z;
or using validate function:
RecTo.VALIDATE(A,RecFrom.X);
...
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
In codeunit if I use following
IF recFrom.FIND('-") THEN
The the compilation error says that I have to declare a global variable
recFrom. Now I do not know how to make a table as global variable.
Thanks and regards
Kumar
Select menu View / C/AL Globals and enter:
Name=recFrom
DataType=Record
Subtype=<Your table>
<Your table> can be selected from list or you type in the Table ID or TableName. You can type only part of name, but it must be selective...
How is your recTo defined ? You should define vars before writing code. Then you can use F5 (Symbol Menu) to select from defined varibles (records and fields), functions, etc. to build your code.
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
I wrote the following code and compiled it declaring the variables as told by you.
IF recFrom.FIND('-') THEN
BEGIN
REPEAT
recFrom.TRANSFERFIELDS(recTo);
recTo.INSERT;
UNTIL recFrom.NEXT = 0;
END
It compiles well. But nothing happens. No record is populated in the recTo table. Do I have to set up some properties like InitValue etc. of
table or key field .
Thank you very much and best regards
Kumar
Definition from Help>
I means that>
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
Instead it gives me folllowing error
recTo indexNo 0 already exists
In the recTo table indexNo is the first field and the table is empty.
Best regards
Kumar
May be, that fields in recTo have another FieldNo that in recFrom... TransferFields transfer values from fields with same no. as destination fields.
Can you post there structure of your two tables? (list of fields, types, field nos.)
:?:
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
recFrom table
No , Integer , Field No 1
Identification , Text , Field No 2
OrderNumber , Text , Field No 3
Date , Date , Field No 4
Inventory , Text , Field No 5
Qty , Integer , Field No 6
recTo table
Serial , Integer , Field No 1
IdNumber , Text , Field No 2
OrderNumber , Text , Field No 3
Date , Date , Field No 4
SKU , Text , Field No 5
Qty , Integer , Field No 6
This is the code
IF recFrom.FIND('-') THEN
BEGIN
REPEAT
recTo.TRANSFERFIELDS(recFrom);
recTo.INSERT;
UNTIL recFrom.NEXT = 0;
recFrom.DELETEALL;
END
This is the error message
recTo Serial 0 already exists
regards
Kumar
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
Kumar
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
RIS Plus, LLC
IF recFrom.FIND('-') THEN
BEGIN
REPEAT
recTo.TRANSFERFIELDS(recFrom);
IF NOT recTo.INSERT THEN
recTo.MODIFY;
UNTIL recFrom.NEXT = 0;
recFrom.DELETEALL;
END
then codeunit compiles well and on runing it gives no error message but no record is inserted in recTo table. However last statement executes and rows in recFrom table are deleted.
Regards
Kumar
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
but i would write the code
IF recFrom.FIND('-') THEN
BEGIN
REPEAT
recTo.TRANSFERFIELDS(recFrom,true);
IF recTo.INSERT THEN; // this wiil not acure an error if cant insert
UNTIL recFrom.NEXT = 0;
recFrom.DELETEALL;
END