Create Add Bonus button under Sales Order

BrianBirkBrianBirk Member Posts: 3
Hi Everyone.

Using Navision 4.0.

And I'm a complete newbie, sorry. If the question has been answered elsewhere then please don't yell at me :-) Just tell me the link, pretty please :-) :-)

I would like to create a button named 'Bonus' under Sales Order.

When the button is clicked the 'Unit Price excl. VAT' should be subtracted 10% (Just an example).

Ok, what I have done so far is the following.

Created the button 'Bonus' under Sales Order.
Linked that button to a function named 'AddBonus' under the form 'Sales Order Subform'.

Now I'm stucked as I have no idea how to enumerate through the lines of the current order to subtract the 10%.

I already know that this can be setup elsewhere in Navision, but I would like to know how to do it programmatically.

So actually to make it simple: How do I enumerate through the lines of the TableBox, so that:
"Unit Price" := "Unit Price" * 0.9;
is done on all lines instead of only the selected one?

Answers

  • matttraxmatttrax Member Posts: 2,309
    I won't tell you exactly how to do it, but I will point you in the right direction. It'll be much more helpful since you are starting out.

    First off, put your function in the Sales Header table, not the subform. That way you can call the function on any order from anywhere that the record is used.

    Next, you need to figure out the relationship between the Sales Header and Sales Line table if you do not already know it. Take a look at the properties on the subform control from the main form and you will see how it is "linked".

    Finally, search the forum or read the documentation about SETFILTER and REPEAT UNTIL loops. These are the two constructs you need in order to move through the appropriate lines.

    Try these out, come up with your code, and if it doesn't work post it here and we can point you more in the right direction. Good luck. :D
  • BrianBirkBrianBirk Member Posts: 3
    mattrax, thank you very much for pointing me in the right direction.

    Everything works perfectly now thanks to you :-)

    I created a variable named salesline pointing to the report Sales Lines

    and add this code
      salesline.SETFILTER( "Document No.","No.");
    IF salesline.FINDSET THEN BEGIN
      REPEAT
             IF salesline."No." <> '' THEN
             MESSAGE(salesline.Description);
      UNTIL salesline.NEXT = 0;
    END;
    

    Above was just for testing and it works like a charm.

    Thanks again
  • matttraxmatttrax Member Posts: 2,309
    One thing you will want to add is a filter for the document type as well. You never know when you will have a Quote and an Order with the same number. In that case your code would do more than it should as it would process for both documents.
  • SavatageSavatage Member Posts: 7,142
    as stated above also adding
    salesline.SETFILTER( "Document Type","Document Type");

    will help insure you are updating the proper order

    You'll also have to throw in a
    Salesline.modify;
    to save your changes
Sign In or Register to comment.