Salesheader table creates a blank no.

bianconeribianconeri Member Posts: 7
Im trying to import invoices to salesheader table. If i import one invoice it works fine, but if i import multiple invoices then i get this error: "The Sales Header already exists. Identification fields and values: Document type='Invoice,No=''

Here is the code

IF fl.FINDFIRST THEN
REPEAT
MySalesHeader.INIT;
MySalesHeader."Posting Date" := TODAY;
MySalesHeader."Document Date" := TODAY;
MySalesHeader."Document Type" := MySalesHeader."Document Type"::Invoice;
MySalesHeader.VALIDATE("Sell-to Customer No.", fl.debet);
MySalesHeader.INSERT;
UNTIL fl.NEXT = 0;

fl is the table with the imported invoices

Any idea what is wrong here?

Thank you in advance :)

Answers

  • pawanppawanp Member Posts: 90
    bianconeri wrote:

    IF fl.FINDFIRST THEN
    REPEAT
    MySalesHeader.INIT;
    MySalesHeader."Posting Date" := TODAY;
    MySalesHeader."Document Date" := TODAY;
    MySalesHeader."Document Type" := MySalesHeader."Document Type"::Invoice;
    MySalesHeader.VALIDATE("Sell-to Customer No.", fl.debet);
    MySalesHeader.INSERT;
    UNTIL fl.NEXT = 0;

    You are not assigning any value to "No."
  • AlbertvhAlbertvh Member Posts: 516
    Try this
    CLEAR(MySalesHeader);
    

    before the INIT statement or MySalesHeader."No." := '';

    Hope this helps
  • bianconeribianconeri Member Posts: 7
    When Sales header initializes No. is automatically assigned.. increment by 1
  • bianconeribianconeri Member Posts: 7
    I have tried CLEAR(MySalesHeader) and MySalesHeader."No." := ''

    But I keep getting the same error.. Sales Header already exists.
  • bianconeribianconeri Member Posts: 7
    Solved :)

    Instead of typing insert I typed insert(true)

    Thank for your help
Sign In or Register to comment.