Copy field data from sales order page to custom tables.

ManiNavManiNav 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.

Best Answer

Answers

  • SanderDkSanderDk Member Posts: 497
    You need to added a repeat statement.
    Change your code to
    IF 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.
  • ManiNavManiNav Member Posts: 120
    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.
  • lhlDKlhlDK Member Posts: 10
    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;
  • ManiNavManiNav Member Posts: 120
    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,
    Mani
  • ManiNavManiNav Member Posts: 120
    Hi lhlDK,

    Thanks alot, I got it.

    Thanks,
    Mani.
Sign In or Register to comment.