Using TRANSFERFIELDS

amadman114amadman114 Member Posts: 36
This is really annoying me.

I'm new to Navision, and, as you can probably tell, am still learning the basics.

I want to transfer data from one table to another. When I get this basic part working, I will refine the data.
I am trying to do this with:
GrecDeletedSalesInv.GET;
GrecDeletedSalesInv.TRANSFERFIELDS(SalesInvHeader, FALSE);
GrecDeletedSalesInv.INSERT;

The tables are exact copies of each other (I used save as and just changed the ID/Name)

However whatever I try it doesn't work as desired.
In this case it returns the error:
The Sales Invoice Header already exists.
Identification fields and values:
No.=''

I've made sure there are no records in the table being written to

Comments

  • lvanvugtlvanvugt Member Posts: 774
    How about:
    SalesInvHeader.GET;
    GrecDeletedSalesInv.TRANSFERFIELDS(SalesInvHeader, FALSE);
    GrecDeletedSalesInv.INSERT;
    

    Did you read the help on TRANSFERFIELDS: http://msdn.microsoft.com/en-us/library/dd301438(v=nav.70).aspx?
    Luc van Vugt, fluxxus.nl
    Never stop learning
    Van Vugt's dynamiXs
    Dutch Dynamics Community
  • Miklos_HollenderMiklos_Hollender Member Posts: 1,598
    Please forget Grec, the Navision way is that programmers are supposed to understand the application logic and not blindly follow detailed specs, hence everybody knows a SalesInvHeader variable is a record type, an InvoiceAmount is a decimal type, an InvoiceCount is an integer type etc. and those who don't should not touch the code. It's a way to signal everybody if you are not familiar with the application don't try to maintain my code.

    Your problem is that if you can GET the DeletedSalesInv then it has already been INSERT-ed by some other code. Or by application behavior like user on a form.

    So either remove that other code that did it, or if you consider that correct behavior and in this code you need to modify an existing DeletedSalesInv, use DeletedSalesInv.MODIFY instead of INSERT.
  • lvanvugtlvanvugt Member Posts: 774
    Please forget Grec, ...
    ..., or if you consider that correct behavior and in this code you need to modify an existing DeletedSalesInv, use DeletedSalesInv.MODIFY instead of INSERT.
    :roll: :?:
    Luc van Vugt, fluxxus.nl
    Never stop learning
    Van Vugt's dynamiXs
    Dutch Dynamics Community
  • amadman114amadman114 Member Posts: 36
    Thanks for the replies.

    What I think I was misunderstanding (other than the GET) was that I needed to loop it for it to do it with every line in the range.
    I ended up using
    REPEAT
        CLEAR(GrecDeletedSalesInv);
        GrecDeletedSalesInv.TRANSFERFIELDS(GrecSalesInvHeader);
        GrecDeletedSalesInv.INSERT;
      UNTIL GrecSalesInvHeader.NEXT = 0;
    
  • MBergerMBerger Member Posts: 413
    As lvanvugt already told you, have a look at the help file on TRANSFERFIELDS, especially the part about the primary key fields.
Sign In or Register to comment.