How to copy information from a table in a form?

Five
Member Posts: 32
Hello Navision People!
I have a problem where i run a form.It goes like this :
- a user inputs an item code into a textbox on the form and pushes a command button
- all records with the same itemcode then populate the grid of the form (or sourcetable).
- the user then modifies a field on those records say eg unit cost.
this is where i want to copy all the modified information to another table and clear the one in the form.
i have tried with the transferfields method but keep getting errors.here id the code:
ON PUSH
IF FIND('+') THEN
NextEntryNo :="Table Entry No." +1
ELSE
NextEntryNo := 1;
IF ItemCode <> '' THEN BEGIN
NewItemCode:= ItemCode;
INIT;
NewItemCode:=DELSTR(ItemCode,7);
Item.SETFILTER("No.",'%1',NewItemCode + '*');
IF Item.FIND('-') THEN
REPEAT
i+=1;
IF i=1 THEN BEGIN
IF Item."No." <> ItemCode THEN BEGIN
IF "Table Entry No."=1 THEN BEGIN
"Item No.":=Item."No.";
"Old price":=Item."Standard Cost";
Item.CALCFIELDS(Inventory);
Quantity := Item.Inventory ;
"Person Amending" := USERID;
Date := TODAY;
MODIFY;
//NextEntryNo:= NextEntryNo +1;
END;
END;
END ELSE BEGIN
"Table Entry No.":=NextEntryNo;
"Item No.":=Item."No.";
"Old price":=Item."Standard Cost";
Item.CALCFIELDS(Inventory);
Quantity := Item.Inventory ;
"Person Amending" := USERID;
Date := TODAY;
INSERT;
NextEntryNo:= NextEntryNo +1;
END;
//NextEntryNo:= NextEntryNo +1;
CLEAR(ItemCode);
RESET;
//END;
UNTIL Item.NEXT=0;
END;
table1.INIT; //table1 is an exact copy of the form source table
table1.TRANSFERFIELDS(table);
table1.MODIFY;
i keep getting the error that "table entry 0 already exits".
I set the delayed insert property to yes cos i want "TableEntryNo." to start at 1.
Thank you in advance for your help
I have a problem where i run a form.It goes like this :
- a user inputs an item code into a textbox on the form and pushes a command button
- all records with the same itemcode then populate the grid of the form (or sourcetable).
- the user then modifies a field on those records say eg unit cost.
this is where i want to copy all the modified information to another table and clear the one in the form.
i have tried with the transferfields method but keep getting errors.here id the code:
ON PUSH
IF FIND('+') THEN
NextEntryNo :="Table Entry No." +1
ELSE
NextEntryNo := 1;
IF ItemCode <> '' THEN BEGIN
NewItemCode:= ItemCode;
INIT;
NewItemCode:=DELSTR(ItemCode,7);
Item.SETFILTER("No.",'%1',NewItemCode + '*');
IF Item.FIND('-') THEN
REPEAT
i+=1;
IF i=1 THEN BEGIN
IF Item."No." <> ItemCode THEN BEGIN
IF "Table Entry No."=1 THEN BEGIN
"Item No.":=Item."No.";
"Old price":=Item."Standard Cost";
Item.CALCFIELDS(Inventory);
Quantity := Item.Inventory ;
"Person Amending" := USERID;
Date := TODAY;
MODIFY;
//NextEntryNo:= NextEntryNo +1;
END;
END;
END ELSE BEGIN
"Table Entry No.":=NextEntryNo;
"Item No.":=Item."No.";
"Old price":=Item."Standard Cost";
Item.CALCFIELDS(Inventory);
Quantity := Item.Inventory ;
"Person Amending" := USERID;
Date := TODAY;
INSERT;
NextEntryNo:= NextEntryNo +1;
END;
//NextEntryNo:= NextEntryNo +1;
CLEAR(ItemCode);
RESET;
//END;
UNTIL Item.NEXT=0;
END;
table1.INIT; //table1 is an exact copy of the form source table
table1.TRANSFERFIELDS(table);
table1.MODIFY;
i keep getting the error that "table entry 0 already exits".
I set the delayed insert property to yes cos i want "TableEntryNo." to start at 1.
Thank you in advance for your help

Compile and then Recompile ....
0
Comments
-
Try table1.insert instead of modifyLR0
-
tried it before modify....did not work.
Any other ideas? :?Compile and then Recompile ....0 -
try
table1.TRANSFERFIELDS(table, TRUE);0 -
Tried the above...still does not work!
Any ideas please??Compile and then Recompile ....0 -
Hi
It looks like taht the original Table has had INIT and RESET applied to it, so i am thinking that you will have to do a GET or FIND on the Table before you can do your TRANSFERFIELDS into Table1, then Insert Table 1 not MODIFY.
Or you could write the record to a temporary table before you do the reset, then transfer the temp record into table 1.Answer the question and wait for the answer.0 -
Delete the RESET statement at the end of your loop.0
-
hi wonmo and stepheng
tried both your suggestions....it stilldoes not want to budge.
anyway gonna try plodding on..hopefully something will give.
thanks for trying anyway.Compile and then Recompile ....0 -
Hi Five
Try thisON PUSH () IF FIND('+') THEN NextEntryNo :="Table Entry No." +1 ELSE NextEntryNo := 1; IF ItemCode <> '' THEN BEGIN NewItemCode := ItemCode; INIT; NewItemCode := DELSTR(ItemCode,7); Item.SETFILTER("No.",'%1',NewItemCode + '*'); IF Item.FIND('-') THEN REPEAT i += 1; IF i = 1 THEN BEGIN IF Item."No." <> ItemCode THEN BEGIN IF "Table Entry No." = 1 THEN BEGIN "Item No." := Item."No."; "Old price" := Item."Standard Cost"; Item.CALCFIELDS(Inventory); Quantity := Item.Inventory ; "Person Amending" := USERID; Date := TODAY; MODIFY; Table1.INIT; // table1 is an exact copy of the form source table Table1.TRANSFERFIELDS(table); Table1.Insert; END; END; END ELSE BEGIN "Table Entry No." := NextEntryNo; "Item No." := Item."No."; "Old price" := Item."Standard Cost"; Item.CALCFIELDS(Inventory); Quantity := Item.Inventory ; "Person Amending" := USERID; Date := TODAY; INSERT; Table1.INIT; // table1 is an exact copy of the form source table Table1.TRANSFERFIELDS(table); Table1.Insert; NextEntryNo:= NextEntryNo +1; END; CLEAR(ItemCode); RESET; UNTIL Item.NEXT=0; END; // table1.INIT; //table1 is an exact copy of the form source table // table1.TRANSFERFIELDS(table); // table1.MODIFY;
Answer the question and wait for the answer.0 -
Five,
just a little hint.
If you post code onto the forum just post it in these tags.
[ code ]
...
C/AL Code
...
[ /code ]
Tags without the spaces, I needed to add them so I could post them."Real programmers don't comment their code.
If it was hard to write, it should be hard to understand."0 -
Hello StephenG
tried your advice..still the same error.
thinking of scraping it.
thanksCompile and then Recompile ....0 -
Hi Five.
I've look through your code as well, and the first thing that strikes me is that the Key of your Table1 isn't initialised.
wonmo posted the trick for that IF your are using the same key structure. F.ex. Code20 for both tables. Transferfields with the second option set to TRUE will copy the keys too.
Further analysis shows that the processing is based on the SourceTable of the form, but the Transferfields function copies data from a record named "table". Shouldn't the record "table" be the current record?
If, then my bet would be Table1.TRANSFERFIELDS(Rec, TRUE).
We don't want you to have to delete precious time of coding, now do we..It is impossible to make anything foolproof, because fools are so ingenious.0 -
SoftTod...you are a genius my man.Thank you so much.
I think you should change your name to HardCoreTod..
cos yu kick ass!
thanks alot to the other guys Wonmo.Stepheng....etc
your help was really appreciated.Compile and then Recompile ....0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions