Can't create new Sales Header

Richard_O'BrienRichard_O'Brien Member Posts: 3
I can't get my report to insert a new record into the Sales Header table. The code that I am using to, which is not working, is the following:
  SalesHeader.INIT;
  SalesHeader.VALIDATE(SalesHeader."Document Type",SalesHeader."Document Type"::Invoice);
  SalesHeader.VALIDATE(SalesHeader."No.",'');
  SalesHeader.INSERT(TRUE); 

What happens is that the record seems to be inserted, but upon finishing running the report it is nowhere to be found in the Sales Header table.

Answers

  • girish.joshigirish.joshi Member Posts: 407
    What you are describing is some sort of commit problem.

    Are you running the report from the object designer after saving it? Or are you running the report directly from the report designer (Ctrl+R) ?
  • SavatageSavatage Member Posts: 7,142
    How are you assigning the Sales header no.?

    If you look at the sales header table OnInsert you'll see
    OnInsert()
    SalesSetup.GET;
    IF "No." = '' THEN BEGIN
      TestNoSeries;
      NoSeriesMgt.InitSeries(GetNoSeriesCode,xRec."No. Series","Posting Date","No.","No. Series");
    END;
    InitRecord;
    

    etc etc
  • DenSterDenSter Member Posts: 8,305
    Try just setting the values without validating them.
  • diptish.naskardiptish.naskar Member Posts: 360
    Have you used the Salesheader variable anywhere in the report before writing the code for insert into the sales header?
    Diptish Naskar
    For any queries you can also visit my blog site: http://msnavarena.blogspot.com/
  • distrisoft_larbidistrisoft_larbi Member Posts: 17
    Hi,

    don't use the validate. Just use this:
    SalesHeader.INIT; 
    SalesHeader."Document Type" :=SalesHeader."Document Type"::Invoice; 
    SalesHeader."No." :=''; 
    SalesHeader.INSERT(TRUE); 
    

    [/code]
  • bappaditya44bappaditya44 Member Posts: 14
    Your code is working fine in std Navision .Just check the No Series system is picking and then find the Invoices with that no.
  • Richard_O'BrienRichard_O'Brien Member Posts: 3
    Hi,
    sorry for the late reply and many thanks for all the assistance.
    I am kind of embarrassed to tell you that the problem was that the variable was set to "temporary" :roll:

    So both my code and the one without the validate worked.
  • DenSterDenSter Member Posts: 8,305
Sign In or Register to comment.