How to Create Sales Lines in Test CodeUnit

markclemarkcle Member Posts: 65
Hi All

We're and end user developing some of our own extensions, so we can't use the test tool or test libraries. I need to write tests that insert lines (which will update other items based on an event subscription)

I got as far as opening the sales order in edit mode (hard-coding the sales order no for now), but I'm stuck on how to create a line item. Could anyone point me in the right direction. Here's my proc:
 [Test]
   procedure TestSalesOrderline()
    var
        SalesOrderCard: TestPage "Sales Order";
    begin
        SalesOrderCard.OpenEdit();
        with SalesOrderCard do begin
            GoToKey(1, 'S200020');
            "No.".AssertEquals('S200020');

            // Insert a line with item no 'FLOC'
            OK.Invoke();
        end;
    end;

How would I go about inserting a sales line in this order and then getting the value form one of it's fields?

Thanks

Mark

Answers

  • Maria-SMaria-S Member Posts: 90
    Do you need to test specifically page behaviour?
    Can you insert your lines on table level?
  • markclemarkcle Member Posts: 65
    edited 2020-03-12
    I need to test subscriptions and the code units they run. For example, for certain freight types, when the line total changes (or new lines are added), i need to recalculate the total freight line (and update it) as it is based on a % of $
  • Maria-SMaria-S Member Posts: 90
    which events are your subscriptions are based on? Table events or page events?
  • markclemarkcle Member Posts: 65
    edited 2020-03-12
    These are the two I'm currently using:
    [EventSubscriber(ObjectType::Table, Database::"Sales Line", 'OnAfterModifyEvent', '', true, true)]
    [EventSubscriber(ObjectType::Table, Database::"Sales Line", 'OnAfterInsertEvent', '', true, true)]
    

    I am somewhat puzzled by OnAfterInsite, it triggers twice for every line when I just open a sales order in edit mode. No new lines have been inserted at all, but it still fires twice
  • krikikriki Member, Moderator Posts: 9,112
    [Topic moved from 'NAV Tips & Tricks' forum to 'NAV Three Tier' forum]

    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • ShaiHuludShaiHulud Member Posts: 228
    markcle wrote: »
    These are the two I'm currently using:
    [EventSubscriber(ObjectType::Table, Database::"Sales Line", 'OnAfterModifyEvent', '', true, true)]
    [EventSubscriber(ObjectType::Table, Database::"Sales Line", 'OnAfterInsertEvent', '', true, true)]
    

    I am somewhat puzzled by OnAfterInsite, it triggers twice for every line when I just open a sales order in edit mode. No new lines have been inserted at all, but it still fires twice

    It triggers several times because to calculate the totals, the Page inserts into (temporary) Sales Line table. To avoid that, the first thing your event should check, is if the record is "real" or temporary to avoid such situations.
Sign In or Register to comment.