Inserting data in Navision tables

DredijsDredijs Member Posts: 3
I Have a problem. We are building a webshop. How we can autpmated to put data in navision tables (Sales Header, sales laine, Items...) when client made order in webshop?
The Webshp is using another SQL database, so after order, system should import in table Item a product and update Sales Header andSales line table.
What kind of solution i need? ](*,)

Comments

  • ara3nara3n Member Posts: 9,256
    You simply need NAS to periodicaly monitor the other db and create so. You or NSC has to create the codeunites.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • DredijsDredijs Member Posts: 3
    Thank You.. Where i can find some codeunit samples?
  • ArhontisArhontis Member Posts: 667
    For the NAS installation you should read the w1w1atas.pdf in the product cd.

    Then you you should create a single instance codeunit and call it in the NASHandler funtion in codeunit 1 like:
      IF (COPYSTR(Parameter,1,9) = 'TEST') THEN
        MYCodeunit.RUN;
    
    in the REPEAT statement, just like the:
      IF (COPYSTR(Parameter,1,4) = 'ADCS') THEN BEGIN
    ...
    

    In your codeunit you could query the other database for the data you want and then create the sales lines and headers...
  • ArhontisArhontis Member Posts: 667
    I forgot to mention that you should declare a variable of type Automation: 'Navision Timer 1.0'.Timer in your codeunit and in the OnRun trigger you should do something like that:
    IF ISCLEAR(Timer) THEN BEGIN
      CREATE(Timer);
      Timer.Interval := 60000;//that is 1 minute in milliseconds
      Timer.Enabled(TRUE);
    END;
    
    and set the timer interval to what ever time you want...

    Then in the Timer::Tmer(Milliseconds:Integer) trigger that is created in your codeunit should add your code (or in functions that are called within that trigger)...

    I hope you got the general view of a NAS implementation...
  • ara3nara3n Member Posts: 9,256
    Here is an example of single instance codeunit.

    OBJECT Codeunit 50009 NAS Handler Timer
    {
      OBJECT-PROPERTIES
      {
        Date=10/09/06;
        Time=11:41:53 AM;
        Modified=Yes;
        Version List=TEC01.00;
      }
      PROPERTIES
      {
        SingleInstance=Yes;
        OnRun=BEGIN
                IF ISCLEAR(Timer) THEN
                  CREATE(Timer);
    
                Timer.StartTimer(6000);
    
                IsRunning := TRUE;
              END;
    
      }
      CODE
      {
        VAR
          Timer@1004 : Automation "{DDADD7CC-AD56-4CA6-9C85-22AE76BF21A1} 3.0:{E7414D60-2D83-44C7-826A-FD14557299F0}:'CP Timer'.cTimer" WITHEVENTS;
          IsRunning@1005 : Boolean;
          JobScheduler@1000000002 : Codeunit 50010;
    
        PROCEDURE CodeUnitIsRunning@2() : Boolean;
        BEGIN
          EXIT(IsRunning);
        END;
    
        EVENT Timer@1004::TimerEvent@1();
        BEGIN
          JobScheduler.RUN ;
        END;
    
        BEGIN
        END.
      }
    }
    
    


    Here is the change in CU 1 in NASHandler function I'm using JOBSCHEDULER as my string parameter for NAS

        END;
      IF (COPYSTR(Parameter,1,4) = 'ADCS') THEN BEGIN
        IF STRPOS(Parameter,' ADCSID=') > 0 THEN
          IF EVALUATE(ADCSID,COPYSTR(Parameter,STRPOS(Parameter,'=') + 1)) THEN
            ADCSNASStartup.SetNASID(ADCSID)
          ELSE
            ADCSNASStartup.SetNASID('NAS1');
        ADCSNASStartup.RUN;
        CGNASStartedinLoop := TRUE;
      END;
    
      //S001 Start
      IF (COPYSTR(Parameter,1,8) ='JOBSCHEDULER') THEN BEGIN
          CLEAR(T_MailTimer);
          T_MailTimer.RUN;
        CGNASStartedinLoop := TRUE;
      END;
      //S001 End
    
      IF (COPYSTR(Parameter,1,4) = 'NEP-') THEN BEGIN
        EPNASSetup.GET(Parameter);
        IF EPNASSetup."Front End Processing" THEN BEGIN
          EmployeePortalApplSrv.SetNASID(Parameter);
    



    Here is example on how to create a sales Header. You have to put this in a Codeunit and maybe call it from single instance codeunit.
      CLEAR(SalesHeader);
      SalesHeader.VALIDATE("Document Type", SalesHeader."Document Type"::Order);
      SalesHeader.VALIDATE("No.",'');
      SalesHeader.INSERT(TRUE);
      SalesHeader.SetHideValidationDialog(TRUE);
      SalesHeader.VALIDATE("Sell-to Customer No.", Cust."No.");
      SalesHeader.VALIDATE("External Document No.", "Document No.");
      SalesHeader.VALIDATE("Order Date", "Order Date");
      SalesHeader.VALIDATE("Document Date",WORKDATE);
      SalesHeader.VALIDATE("Salesperson Code","Salesperson Code");
      SalesHeader.VALIDATE("Ship-to Name", COPYSTR("Ship Cust First Name" + ' ' + "Ship Cust Last Name",1,50) );
      SalesHeader.VALIDATE("Ship-to Address", "Shipping Addr1");
      SalesHeader.VALIDATE("Ship-to Address 2", "Shipping Addr2");
      SalesHeader."Ship-to City" := "Shipping City";
      SalesHeader."Ship-to County" := "Shipping State";
      SalesHeader."Ship-to Post Code" := "Shipping Zip";
      SalesHeader."Ship-to Country Code" := "Shipping Country";
      SalesHeader.VALIDATE("Shipment Method Code", "Shipping Code");
      SalesHeader.VALIDATE("Package Code", 'CUSTOM12X12X12');
      SalesHeader."No. of Packages" := 1;
      SalesHeader."Authorization No." := "Authorization Num";
      //SalesHeader.VALIDATE("Coupon/Promotion Code","Promo Code");
      SalesHeader."Invoice Discount Calculation" :=   SalesHeader."Invoice Discount Calculation"::Amount;
      SalesHeader."Invoice Discount Value" := - "Discount Amt";
      SalesHeader.MODIFY(TRUE);
    


    And here is how to create a sales line.
        CLEAR(SalesLine);
        SalesLine."Document Type" := SalesHeader."Document Type";
        SalesLine."Document No." := SalesHeader."No.";
        SalesLine."Line No." := PendingOrderslines."External Line No.";
        SalesLine.INSERT(TRUE);
        SalesLine.VALIDATE(Type,PendingOrderslines.type);
        SalesLine.VALIDATE("No.",PendingOrderslines."No.");
        SalesLine.VALIDATE(Quantity,PendingOrderslines.Quantity);
        SalesLine.VALIDATE("Unit of Measure Code", PendingOrderslines."Unit of Measure");
        SalesLine.VALIDATE("Unit Price",PendingOrderslines.Amount);
        SalesLine.MODIFY(TRUE);
    
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • DenSterDenSter Member Posts: 8,304
    That CP timer object is no longer part of NAV. I am pretty sure that we can simply copy the dll from 4.0 and register it to be used in a 5.0 SP1 tech upgrade. Can anyone confirm this, or do we need to modify the code to use a different timer?
  • ara3nara3n Member Posts: 9,256
    Yes you can register the old cp timer. I've done it for a client and it works.


    I suggest to use the CGTimer. It's the same thing but it comes std with 5.0 and 2009.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • DenSterDenSter Member Posts: 8,304
    Thanks Rashed, I appreciate the quick reply
Sign In or Register to comment.