How to copy information from a table in a form?

FiveFive Member Posts: 32
edited 2004-03-15 in Navision Financials
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 :D
Compile and then Recompile ....

Comments

  • lakshmivallurulakshmivalluru Member Posts: 168
    Try table1.insert instead of modify
    LR
  • FiveFive Member Posts: 32
    tried it before modify....did not work.
    Any other ideas? :?
    Compile and then Recompile ....
  • wonmowonmo Member Posts: 139
    try

    table1.TRANSFERFIELDS(table, TRUE);
  • FiveFive Member Posts: 32
    Tried the above...still does not work!

    Any ideas please?? :cry::cry:
    Compile and then Recompile ....
  • StephenGStephenG Member Posts: 99
    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.
  • wonmowonmo Member Posts: 139
    Delete the RESET statement at the end of your loop.
  • FiveFive Member Posts: 32
    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 ....
  • StephenGStephenG Member Posts: 99
    Hi Five

    Try this

    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;
    
              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.
  • eromeineromein Member Posts: 589
    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."
  • FiveFive Member Posts: 32
    Hello StephenG

    tried your advice..still the same error. :cry:

    thinking of scraping it.

    thanks
    Compile and then Recompile ....
  • Soft_TodSoft_Tod Member Posts: 43
    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.. :D
    It is impossible to make anything foolproof, because fools are so ingenious.
  • FiveFive Member Posts: 32
    SoftTod...you are a genius my man.Thank you so much.

    I think you should change your name to HardCoreTod.. :D
    cos yu kick ass!

    thanks alot to the other guys Wonmo.Stepheng....etc

    your help was really appreciated. :D
    Compile and then Recompile ....
Sign In or Register to comment.