Transferfields

upasanisandip
Member Posts: 405
Hi all,
I want to use TRANSFERFIELD.
SalesOrderEX.SETFILTER(SalesOrderEX."Sales Order No", SalesHeader."No.");
IF SalesOrderEX.FIND('-') THEN
BEGIN
SalesInvoiceEX.INIT;
SalesInvoiceEX.TRANSFERFIELDS(SalesOrderEX);
SalesInvoiceEX.INSERT;
END;
Is the above code correct?
thanks.
I want to use TRANSFERFIELD.
SalesOrderEX.SETFILTER(SalesOrderEX."Sales Order No", SalesHeader."No.");
IF SalesOrderEX.FIND('-') THEN
BEGIN
SalesInvoiceEX.INIT;
SalesInvoiceEX.TRANSFERFIELDS(SalesOrderEX);
SalesInvoiceEX.INSERT;
END;
Is the above code correct?
thanks.
0
Comments
-
Like the help says:
Use this function to copy all matching fields in one record to another record.
It just copies over all matching fields (field number / data type). So the code should work, if both your tabledefinitions are alike.
comments:
- You code is also going to copy over the primary key fields.
- If your record contains a blob field, you should calculate the Blob field before the transferfields... .
It should work (if all reqs are fullfilled) ... what is wrong with it?0 -
TRANSFERFIELDS does NOT copy the primary-key fields (if you also want this to happen, you need to add a secondary parameter : TRUE [see also the online-help for TRANSFERFIELDS])
But I suppose you want to automatically generate a new primary key. In this case this will be the code (I also cleaned up your code a little):SalesOrderEX.RESET; SalesOrderEX.SETCURRENTKEY(Sales Order No"); SalesOrderEX.SETRANGE(Sales Order No",SalesHeader."No."); IF SalesOrderEX.FINDFIRST THEN BEGIN CLEAR(SalesInvoiceEX); // INIT does NOT clean the primary key fields SalesInvoiceEX."Document Type" := SalesInvoiceEX."Document Type"::Invoice; SalesInvoiceEX.INSERT(TRUE); // because "No." is blank, it will generate a new number. SalesInvoiceEX.TRANSFERFIELDS(SalesOrderEX); SalesInvoiceEX.MODIFY(FALSE); END;
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
I'm afraid you're wrong.
From help:If the InitPrimaryKeyFields parameter is set to true, and the records are in the same table, the TRANSFERFIELDS function will change both the timestamp and the Primary Key fields of the destination record.
If the InitPrimaryKeyFields parameter is set to true, and the records are not in the same table, the TRANSFERFIELDS function will change the Primary Key fields of the destination record (if the fields fulfill the conditions specified above) but the timestamp of the destination record will not be changed.
...
InitPrimaryKeyFields
Data type: Boolean
Default value: True
IfI understand correctly, the default value is true, and if it is true, it will change the primary key fields of the destination record (for me, that copying over...).
Anyway, I did one simple test:lrecCustomer.GET('10000'); ltmprecCustomer."No." := '203049'; ltmprecCustomer.INSERT; MESSAGE(ltmprecCustomer."No."); ltmprecCustomer.TRANSFERFIELDS(lrecCustomer); MESSAGE(ltmprecCustomer."No.");
And the second message shows '10000'... .0 -
And I always thought the the default was FALSE. :oops:
Luckily in my programming, I always put code for changing fields (including the primary key) I want to change AFTER the TRANSFERFIELDS. \:D/Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
kriki wrote:And I always thought the the default was FALSE. :oops:
Luckily in my programming, I always put code for changing fields (including the primary key) I want to change AFTER the TRANSFERFIELDS. \:D/
I do this myself as well ... .
Makes things much clearer.0 -
-
Waldo wrote:Well,
a few years ago, I started the concept "lazy programming" at our company. Pretty interesting tips&tricks already
Or a topic in tips&tricks?
Maybe others can add tips to it.Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
That should really be called "how to make things easier on yourself"0
-
:-) I am definitely lazy programmer, I am able to spent 5 hours of programming to develop tool, which will solve some problem in 2 minutes (without the tool the problem will be solved manually in 2 hours...) :-) - but yes, next time I will have same problem it will be just 2 minutes to solve it.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