Copy field data from sales order page to custom tables.
ManiNav
Member Posts: 120
Hi Everyone,
I am trying to copy the field data from sales order page to my custom tables. ie the sales header table field data to my one custom table and sales line table field data to my another custom table by the clicking custom action button(custom button is on sales order page). I tried some code in Custom button: on action(), I am able to get the first record of sales header and sales line in my corresponding custom tables, as i write the code for: This is my code-
Salesheader.RESET;
IF Salesheader.FINDFIRST THEN
CusSalesheaderM.INIT;
CusSalesheaderM."Document Type" :=Salesheader."Document Type";
CusSalesheaderM."Sell-to Customer No." :=Salesheader."Sell-to Customer No.";
CusSalesheaderM."No." :=Salesheader."No.";
CusSalesheaderM."Ship-to Name" :=Salesheader."Ship-to Name";
CusSalesheaderM."Order Date" :=Salesheader."Order Date";
CusSalesheaderM.INSERT;
Salesline.RESET;
IF Salesline.FINDFIRST THEN
CusSaleslineM.INIT;
CusSaleslineM."Document Type" := Salesline."Document Type";
CusSaleslineM."Sell-to Customer No." := Salesline."Sell-to Customer No.";
CusSaleslineM."Document No." := Salesline."Document No.";
CusSaleslineM."Line No." := Salesline."Line No.";
CusSaleslineM.Type := Salesline.Type;
CusSaleslineM."No." := Salesline."No.";
CusSaleslineM.Quantity := Salesline.Quantity;
CusSaleslineM.INSERT;
But, As I mention above, I want to copy the current data of sales order page, when i click the custom action button.
Please guide me, how can i get this.
Thanks,
Mani.
I am trying to copy the field data from sales order page to my custom tables. ie the sales header table field data to my one custom table and sales line table field data to my another custom table by the clicking custom action button(custom button is on sales order page). I tried some code in Custom button: on action(), I am able to get the first record of sales header and sales line in my corresponding custom tables, as i write the code for: This is my code-
Salesheader.RESET;
IF Salesheader.FINDFIRST THEN
CusSalesheaderM.INIT;
CusSalesheaderM."Document Type" :=Salesheader."Document Type";
CusSalesheaderM."Sell-to Customer No." :=Salesheader."Sell-to Customer No.";
CusSalesheaderM."No." :=Salesheader."No.";
CusSalesheaderM."Ship-to Name" :=Salesheader."Ship-to Name";
CusSalesheaderM."Order Date" :=Salesheader."Order Date";
CusSalesheaderM.INSERT;
Salesline.RESET;
IF Salesline.FINDFIRST THEN
CusSaleslineM.INIT;
CusSaleslineM."Document Type" := Salesline."Document Type";
CusSaleslineM."Sell-to Customer No." := Salesline."Sell-to Customer No.";
CusSaleslineM."Document No." := Salesline."Document No.";
CusSaleslineM."Line No." := Salesline."Line No.";
CusSaleslineM.Type := Salesline.Type;
CusSaleslineM."No." := Salesline."No.";
CusSaleslineM.Quantity := Salesline.Quantity;
CusSaleslineM.INSERT;
But, As I mention above, I want to copy the current data of sales order page, when i click the custom action button.
Please guide me, how can i get this.
Thanks,
Mani.
0
Best Answer
-
What is your key for CusSaleslineM?
Be sure to include 'Document Type', 'Document No' and 'Line No' in this.5
Answers
-
You need to added a repeat statement.
Change your code toIF Salesheader.FINDSET(FALSE,FALSE) THEN Repeat //Rest of your code UNTIL SalesHeader.Next = 0;
If your field number match the once in sales header, you can use the TRANSFERFIELD option instead of manually entering your fields.For help, do not use PM, use forum instead, perhaps other people have the same question, or better answers.0 -
Hi SanderDk,
Thank you so much for reply,
As I mention above that, I need to copy the current data from sales order page. eg- If i select randomly any sales order and I click custom button, it should copy the current data whatever is in page to my custom table. but as you suggest above it will copy the data of last value from the table, i tried your code.
And my field number doesn't match in sales header, just i want to copy some field data to my custom table.
So, please guide me to get my requirement.
Thanks,
Mani.0 -
Should be something like this:
Salesheader.GET("Document Type", "No.");
CusSalesheaderM.INIT;
CusSalesheaderM."Document Type" :=Salesheader."Document Type";
CusSalesheaderM."Sell-to Customer No." :=Salesheader."Sell-to Customer No.";
CusSalesheaderM."No." :=Salesheader."No.";
CusSalesheaderM."Ship-to Name" :=Salesheader."Ship-to Name";
CusSalesheaderM."Order Date" :=Salesheader."Order Date";
CusSalesheaderM.INSERT;
SalesLine.SETRANGE("Document Type", Salesheader."Document Type");
SalesLine.SETRANGE("Document No.", Salesheader."No.");
IF Salesline.FINDSET THEN REPEAT
CusSaleslineM.INIT;
CusSaleslineM."Document Type" := Salesline."Document Type";
CusSaleslineM."Sell-to Customer No." := Salesline."Sell-to Customer No.";
CusSaleslineM."Document No." := Salesline."Document No.";
CusSaleslineM."Line No." := Salesline."Line No.";
CusSaleslineM.Type := Salesline.Type;
CusSaleslineM."No." := Salesline."No.";
CusSaleslineM.Quantity := Salesline.Quantity;
CusSaleslineM.INSERT;
UNTIL SalesLine.NEXT = 0;0 -
Hi lhlDK ,
Thanks, its working for single line, but its showing error for multiple line (ie if in a sales order, more than one line is present). then after clicking button error is: CusSaleslineM already present.
Thanks,
Mani0 -
What is your key for CusSaleslineM?
Be sure to include 'Document Type', 'Document No' and 'Line No' in this.5 -
Hi lhlDK,
Thanks alot, I got it.
Thanks,
Mani.0
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K 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
- 610 NAV Courses, Exams & Certification
- 1.9K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 251 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions
