Navision imorting invoices issue

mhitendramhitendra Member Posts: 6
Hi,

I am programmer by profession and am new to navision. We had a requirement to import invoices generated on our CRM system directly to navision.

I would go bit in detail here, we have built a dataport to import invoices to navision from our CRM system. Now the dataport includes 3 tables, Sales Header, Sales Lines & Document Dimension, we create a csv file to match the dataport and the invoices were being imported fine for a month. After a lot of debugging the posting of the inovices also works perfectly. But we stumbled into to a problem now, when we try to import a new invoice for the same customer (whose invoice was posted successfully last month), the import gives the following error:

The following C/AL functions can be used only to a limited degree during write transactions (because one or more tables will be locked).

Form.RunModal() is not allowed in write transactions.

CodeUnit.Run() is allowed in write transactions only if the return value is not used. For example, 'OK := CodeUnit.Run()' is not allowed.

Report.RunModal() is allowed in write transactions only if 'RequestForm = FALSE'. For example, 'Report.RunModal(...,FALSE)' is allowed.

DataPort.RunModal() is allowed in write transactions only if 'RequestForm = FALSE'. For example, 'DataPort.RunModal(...,FALSE)' is allowed.

Use the COMMIT function to save the changes before this call, or structure the code differently.

Not sure what this error means, we are trying to frantically look around for a solution. Would appreicate if one of you guys can possibly help us with this.

Thanks and regards

Hitendra

Comments

  • selece28selece28 Member Posts: 316
    Hi, This error usually happens when you run one of those RUN or RUNMODAL improperly, Did you do posting routine after import the Sales Header?

    Thanks
    ______________

    Regards,
    Steven
  • XypherXypher Member Posts: 297
    edited 2008-04-29
    I have recently had troubles with this error message and it was a pain in the butt for me to get around it. #-o

    Similar to what selece28 has said but to further explain (to the best of my knowledge)...

    When you launch a Form, Report, DataPort with RUNMODAL (or CodeUnit with RUN) the one or more tables associated with these objects are locked. This cannot happen if there is a write transaction currently in progress.

    COMMIT can be used to end the current write transaction but in a lot of cases using this command can and will be a big "no-no". [-X

    [edit]
    what matttrax said... yeah I got it all wrong :-#
  • matttraxmatttrax Member Posts: 2,309
    If you use RUNMODAL, the object begin run is displayed on the screen and the user must interact with it in some way to get the process to complete. This is not allowed during a transaction because those tables being written to are locked, thus not allowing anyone else to write to them. The information is not made permanent in the database yet.

    So if you get called away, or forget that you're supposed to hit OK, then the table is locked until you remember.

    To make the information stay in the database the transaction has to complete or you have to use a COMMIT statement. COMMIT unlocks any tables are you are writing to and close the transaction. So if a RUNMODAL comes after it there is no transaction occurring and thus no table locks.

    You should avoid using COMMIT unless you absolutely have to. If you get an error later in your code that should have stopped processing all of your information will still be saved in the database. It also take significantly longer if you are committing after every INSERT / MODIFY.

    Hope that helps.
  • ara3nara3n Member Posts: 9,256
    My guess the reason you are getting the message is because of creditwarning dialog openining up.

    You need to set SetHidedialogue function as you are inserting the header and the line.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • mhitendramhitendra Member Posts: 6
    Thanks for your reply guys. But just for your infomation we are not navision experts and have created the dataport in quite the normal way by selecting the tables and fields in a sequence. Then generating a CSV file to match the format and run the dataport, for which we select the CSV file generated.

    Now the problem here is that if we try to import an invoice for a company (in the Sales Header) who has already a posted invoice in the "Sales Invoice Tables", we get the above error, but if we try importing for a new company using the same dataport, it goes in fine, hence, I don't understand that if this error comes as the table is locked or not commited then how does it accept the transaction for other companies. And above all we are not also importing directly to the "Sales Invoice Table" but to the initial "Sales Header" which we then go through normal posting routine.

    Any help or suggestions really appreciated.

    Thanks

    Hitendra
  • mhitendramhitendra Member Posts: 6
    We tried importing the data one by one table and found that the error was because of the "CallFieldValidate" was enabled for fields SellToCustomer & BillToCustomer for the Sales Header table in the dataport. But this option will give an error (when checked) only while trying to import invoices for companies who already have a posted invoice in the "Sales Invoice Header" table.

    We know disabling the CallFieldValidate check is not advisable, can any of you please suggest what the problem might possibly be. Or is there a way to check what does the CallFieldValidate function for SellToCustomer actually does, does it look for a key or something why it gives the error?

    Thanks
  • AlbertvhAlbertvh Member Posts: 516
    Hi

    You should turn the debugger on and see where you get this error. As the others have said it could be in the credit limit check. so do the following

    before clicking on Ok of the dataport Click Tools -> Debugger -> Active make sure that Breakpoint on Triggers is not ticked.


    Albert
  • julkifli33julkifli33 Member Posts: 1,087
    i have the same problem here...
    while using my own notebook, it just fine
    but in customer.... it appears warning like that
    what should i do? anyone can help?
  • kitikkitik Member Posts: 230
    Have you read all posts in this thread? Have you tried any of the possible solutions given?

    You are getting this error because a form is poping up in the middle of a transaction. Put the debugger on to see wich form and why.

    Salut!
    Laura Nicolàs
    Author of the book Implementing Dynamics NAV 2013
    Cursos Dynamics NAV (spanish) : http://clipdynamics.com/ - A new lesson released every day.
  • julkifli33julkifli33 Member Posts: 1,087
    kitik wrote:
    Have you read all posts in this thread? Have you tried any of the possible solutions given?

    You are getting this error because a form is poping up in the middle of a transaction. Put the debugger on to see wich form and why.

    Salut!

    yes... after i debug the error is right here
    .
    .
    .

    END;
    SalesLine.Type := 2;
    SalesLine.SetHideValidationDialog(TRUE);
    SalesLine.VALIDATE(SalesLine."Cross-Reference No.",ItemCode);
    SalesLine."Quantity" := ItemQuantity;
    SalesLine."Ship-To Code" := SalesHeader."Ship-to Code";
    SalesLine.VALIDATE(SalesLine."Unit Price",NetPrice);
    SalesLine.INSERT(TRUE);
    .
    .
    .
    .
  • ara3nara3n Member Posts: 9,256
    well try and create the line manually and see what happens.

    My guess a form will pop up. You probably have to change the code and not validate.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • julkifli33julkifli33 Member Posts: 1,087
    ara3n wrote:
    well try and create the line manually and see what happens.
    My guess a form will pop up. You probably have to change the code and not validate.

    if we create the sales line manually it just fine...
    no problem
  • kitikkitik Member Posts: 230
    Keep debugging... what line of code inside the OnValidate trigger trows the error? Even more, maybe the error is thrown inside a function the OnValidate calls...

    Salut!
    Laura Nicolàs
    Author of the book Implementing Dynamics NAV 2013
    Cursos Dynamics NAV (spanish) : http://clipdynamics.com/ - A new lesson released every day.
  • ara3nara3n Member Posts: 9,256
    make sure it's the same data when inserting the line manually.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
Sign In or Register to comment.