Options

Insert Line Record - Issue

rajinivmrajinivm Member Posts: 42
Hi Guys,
I'm trying to insert a new line record in Sales Line Table from Sales Invoice form. System is throwing a following error.
"You cannot make any changes in the database until a transaction has been started"

Can you please let me know how can i overcome this issue in C/SIDE?

Thanks and Regards
Rajini

Comments

  • SavatageSavatage Member Posts: 7,142
    I'm trying to remember because i have seen this - but are you sure the header is properly filled out before adding lines?
  • rajinivmrajinivm Member Posts: 42
    Yes Ruiz....First, I have saved Header Level Transactions. and then Im trying to add a new line level record in sales line table. That time I got this issue.
  • SavatageSavatage Member Posts: 7,142
    edited 2009-05-29
    Header Level Transactions? I never heard it put this way before.

    Are you doing something other than order entry thru the form?
    is this error coming due to a dataport or something?

    Have you tried turning on the debugger and seeing where it is stopping?

    Also I've seen that 5.0 SP1 fixes..
    8/27/2008. KB 954722. Build 27253. "Microsoft Dynamics NAV can crash in certain situations. Some times, you will receive this error message:You cannot make any changes in the database until a transaction has been started."Or, "Error 1247 in module 19". Or, some times the NAV application will just terminate."

    edit..
    ..More info needed on what you are trying to do that causes this error.
  • kapamaroukapamarou Member Posts: 1,152
    Are you trying to modify / insert records from special triggers on the form? Some triggers don't allow changes in the database.
  • rajinivmrajinivm Member Posts: 42
    I added a field for FreightAmount in Sales Invoice Form. The new line should be generated in Sales line Window when Im leaving the focus from Freigth Field. I have written a code in Freight Amount - On After Input Trigger.

    Code like this:

    NVSalesLine.INIT;
    NVSalesLine."Document Type":=2;
    NVSalesLine."Document No.":='1005';
    NVSalesLine."Line No.":=10000;
    NVSalesLine.Quantity:=1;
    NVSalesLine."Unit Price":=1.55;
    NVSalesLine.INSERT(FALSE);

    I'm getting error message from last line.
  • kapamaroukapamarou Member Posts: 1,152
    So you can't modify the database from this trigger...

    Usually such code is placed on the Table object, on the OnValidate trigger of a field for example. Do you need this code on the form?

    Also try other triggers like OnValidate of the field on the form...
  • SavatageSavatage Member Posts: 7,142
    Or create a function that you call from a command button or menu item

    OnPush()
    IF Status = Status::Open
     THEN BEGIN
      Salesline.RESET;
      Salesline.SETRANGE(Salesline."Document Type","Document Type");
      Salesline.SETRANGE(Salesline."Document No.","No.");
       IF Salesline.FIND('+')
        THEN BEGIN
         Salesline."Line No." := Salesline."Line No."+ 10000;
         Salesine.Type := Salesline.Type::"Item";
         Salesline.VALIDATE(Salesline."No.","Your Set Item #");
         Salesline.VALIDATE(Salesline.Quantity,1);
         Salesline.VALIDATE(Salesline."Direct Unit Cost",1.55);
         Salesline.INSERT;
        END;
    END
     ELSE BEGIN
      MESSAGE('Sales Order %1 must be open!',"No.");
    END;
    

    Note: I would change where you have hardcoded values such as a qty/price/& item# & put it in a setup table where you can change the values if need be.
  • rajinivmrajinivm Member Posts: 42
    Thanks to all. It's working fine after moving the code to On Validate Event.

    But, Records are not displayed in Invoice Subform (Line Detailes) immediately. Its displayed once I close and open the window.

    This is the code I added for displaying the new record.

    NVSalesInvoiceSubForm.GETRECORD(NVSalesLine)

    Do you know any other method for displaying record?

    Thanks,
    Rajini
  • SavatageSavatage Member Posts: 7,142
    onaftervalidate
    currform.update;
  • rajinivmrajinivm Member Posts: 42
    Thanks Ruiz....
Sign In or Register to comment.