Line Discount Based on Payment Terms

I would like to add a customer in and out of a customer discount group based on their payment terms. This is what I’m doing now.

  1. Create an order

  2. Add items to the order

  3. Change the payments terms to CASH

  4. Since it is cash I change the sales header. Customer discount Group to CASH

If I add new lines to the order they get the discount, but the ones I already added do not. What is the best way to update those lines? I want to make this fool proof so I don’t want to tell people, make sure you change the terms before entering items. Thanks

You need to write code on Sales header table Customer Disc. Group field onvalidate

loop through all the sales lines of sales header and validate Customer Disc. Group field…

This is what I tried…

Customer Disc. Group - OnValidate()

TESTFIELD(Status,Status::Open);

MessageIfSalesLinesExist(FIELDCAPTION(“Customer Disc. Group”));

// Loop through the sales lines and set discount

SalesLine.SETRANGE(“Document Type”,“Document Type”);

SalesLine.SETRANGE(“Document No.”, “No.”);

IF SalesLine.FIND(’-’) THEN BEGIN

REPEAT

SalesLine.“Customer Disc. Group” := “Customer Disc. Group”;

SalesLine.VALIDATE(SalesLine.“Customer Disc. Group”);

SalesLine.MODIFY;

UNTIL SalesLine.NEXT = 0;

END;

Which does not seem to work,

Nevermind, I got it working. I put the code in the payment terms code onvalidate! Duh! :slight_smile:

Now what is the best way to have the form update so I don’t need to forward a record and then go back? I tried CurrForm.UPDATECONTROLS; on the payment terms code - onaftervalidate.

Thanks for the help!

NM…again

CurrForm.UPDATE; worked