Value passed through webservice is Blank on ONInsert Trigger

aavioaavio Member Posts: 143
edited 2012-07-17 in NAV Three Tier
Hi Dears!!!...

I am trying to create sales order from a web application using NAV web services. And i need NAV to generate Sales Order No based on user Store location. I have provided No. Series setup based on Store location. and i am passing Store Location also along other order details in header(customer no, order date... etc) through web services. and upon calling CREATE(ref objSO), Store location seems blank in NAV Table 36 ONInsert trigger.

dont understand why its blank. please any help...
Only primary key values will be available inside NAV ONInsert trigger?

please help me to find a solution to generate sales order No. series based on Store Location passed through webservice.

Thank you,
aav!o

Comments

  • ichladilichladil Member Posts: 68
    Hi aavio,

    I believe that this is a feature (even though I have not found it in any documentation). When I tested it in multiple scenarios the service.Create always called in NAV INSERT first for primary key columns only and MODIFY for the rest afterwards. This behaviour did not change even with delayed Insert nor in NAV2013.

    Therefore my suggestion would be to create and expose a codeunit with function that will create the sales header for you and process it via page only once the sales order exists. Alternatively you may use XMLPort via web service to import sales order.

    Regards, Igor
  • yukonyukon Member Posts: 361
    Hi aavio,

    If your SO no. want to follow base on your setup you can modify at T36 - GetNoSeriesCode(). Or you can set "No. Series" when you create Order by ws.

    eg.

    _saleshdr.No_Series = "SO";
    _ws.Create(ref _saleshdr);

    Regards,
    Yukon
    Make Simple & Easy
  • aavioaavio Member Posts: 143
    Dear yukon, i tried to set as

    _saleshdr.No_Series = "SO";
    _ws.Create(ref _saleshdr);

    but still No. Series seems to blank on OnInsert trigger. i am getting error messages like that.
    aav!o
  • kinekine Member Posts: 12,562
    For me no problem and all is working as expected:
                var port = new NAV.Test_PortClient();
                var test = new NAV.Test();
                test.Document_Type = NAV.Document_Type.Order;
                test.Document_TypeSpecified = true;
                test.No_Series = "aaaa";
                port.Create(ref test);
    

    It ends with "aaaa" is not a No. Series... it means that the value is transfered correctly. Of course, I just needed add the No. Series field to the page and se the EDITABLE property to TRUE for it.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • aavioaavio Member Posts: 143
    Dear Kine,
    i tried as you have mentioned. but still No. Series is blank.





    what may be the issue? plz help.

    on salesheader table onInsert trigger i have the code
        IF ISSERVICETIER THEN
          lvOrderNo := NoSeriesMgt.GetNextNo("No. Series",TODAY,TRUE)
        ELSE
          lvOrderNo := NoSeriesMgt.GetNextNo(GetNoSeriesCode,TODAY,TRUE);
    

    suppose if i hardcode No series as lvOrderNo := NoSeriesMgt.GetNextNo('874SO',TODAY,TRUE)
    its working!! and "No. Series" in header is updated.
    ie, When control is in OnInsert trigger "No. Series" blank.
    how to correct it....... ](*,) :(
    aav!o
  • yukonyukon Member Posts: 361
    Hi aavio,
    I believe that this is a feature (even though I have not found it in any documentation). When I tested it in multiple scenarios the service.Create always called in NAV INSERT first for primary key columns only and MODIFY for the rest afterwards. This behaviour did not change even with delayed Insert nor in NAV2013.

    Therefore my suggestion would be to create and expose a codeunit with function that will create the sales header for you and process it via page only once the sales order exists. Alternatively you may use XMLPort via web service to import sales order.

    Regards, Igor

    So, if you want to your no. is following No. Series you may need to use Code Unit and publish. We can be set No. Series but no. is not follow our no. series.
    You can check this way for your No. Series is pass or not.
    Sales Header OnInsert Trigger
            Error('No. %1 - No. Series %2',"No.","No. Series");
    
    C#
                wsSalesHdr.Sales_Order_Service _wsSalesHdr = new wsSalesHdr.Sales_Order_Service();
                _wsSalesHdr.UseDefaultCredentials = true;
    
                wsSalesHdr.Sales_Order _salesorder = new wsSalesHdr.Sales_Order();
                _salesorder.No = "12345";
                _salesorder.No_Series = "S-ORD-2";
                _wsSalesHdr.Create(ref _salesorder);
                _wsSalesHdr.Dispose();
    
    

    If i not mistaken better way is Igor's suggestion. :D

    Regards,
    Yukon
    Make Simple & Easy
  • mikmik Member Posts: 79
    Hi!
    I believe that this is a feature (even though I have not found it in any documentation). When I tested it in multiple scenarios the service.Create always called in NAV INSERT first for primary key columns only and MODIFY for the rest afterwards. This behaviour did not change even with delayed Insert nor in NAV2013.

    Therefore my suggestion would be to create and expose a codeunit with function that will create the sales header for you and process it via page only once the sales order exists. Alternatively you may use XMLPort via web service to import sales order.

    Regards, Igor

    I noticed this as we implemented CRM Connector for NAV on custom pages. If you want to insert a job order then you can not execute code where it really needs to be an order. Status field will always be empty (=quote) OnInsert.

    With kind regards
    mik
  • kinekine Member Posts: 12,562
    Even when you set the "HaveValue" flag for the field?
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • ichladilichladil Member Posts: 68
    Hi Kine,

    back to your sample:
    test.Document_Type = NAV.Document_Type.Order;
    test.Document_TypeSpecified = true;
    test.No_Series = "aaaa";
    service.Create(ref test);

    Yes, this code complains about non-existent no. series. But it still seems to process the Create action in the following steps internally:

    1) Populate Primary Key columns from the request.
    2) INSERT(TRUE)
    3) Populate all other fields
    4) MODIFY(TRUE)

    whereas I often wanted it to process it in the following way (or at least when Delayed insert is used):
    1) Populate all fields.
    2) INSERT(TRUE)

    I have spent quite some time trying to persuade standard NAV page to process it in different way but without success. If you want to really test that it works as I said, put the TESTFIELD on No. Series into OnInsert. I very much believe it will be blank and in your example it complains on non-existing No. Series in step (3).

    Regards,
    igor
  • kinekine Member Posts: 12,562
    Ok, I will try… may be the error is from the table relation validation and not from the code in OnInsert… that's true...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • pi8ikospi8ikos Member Posts: 1
    Guy any news for this? It seems that the OnInsert trigger is executed only for the primary key. Although that the record is correctly inserted, in the OnInsert trigger of the table, the values of all fields except from the primary key are set to their default value.
Sign In or Register to comment.