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
Compile and then Recompile ....
Comments
Any other ideas? :?
table1.TRANSFERFIELDS(table, TRUE);
Any ideas please??
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.
tried both your suggestions....it stilldoes not want to budge.
anyway gonna try plodding on..hopefully something will give.
thanks for trying anyway.
Try this
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.
If it was hard to write, it should be hard to understand."
tried your advice..still the same error.
thinking of scraping it.
thanks
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..
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.