I have extended the discpercent() display method in the Sales Line table using COC to calculate the discount dynamically based on the Sales Pool ID. when I select the salespoolid,the display value is showing correct,but if I modify the salespoolid again from the header,the value reflecting for the new lines and not for the existing lines. I had override the modified ds method of salespoolid by calling salesline_ds.executequery()/research () but still no luck.
The whole idea sounds strange to me. Your change of the display won’t change how discounts are calculated, therefore you’ll show users wrong information.
If you want to take sales pools into account when determining prices and discounts, you’ll need to do it in classes like PriceDisc
.
Regarding the display method, there is an important concept that you have to learn about: Display methods and Form Observability.
Hi Martin,
Business requirement is to add free of charge based on the salespoolid,so that the discpercent will be 100 else 0. I had override the discpercent method from salesline to include the above logic. As i mentioned it’s giving the result properly when I select for the new lines after changing the salespoolid in the header.But the user may change the salespoolid after creating the lines as well,in that case it should update the discpercent value for the lines created .
[Extensionof (tablestr(salesline))]
public final class test
{
public static discpercent discpct()
{
next discpct();
if(salespool::find(this.salesid).salespoolid).FreeOfCharge)
{
discpct = pricedisc::discpct(100,100,100)
}
return discpct;
,}
Can you guide me on this?
Have you read my reply at all? It seems like you missed both parts.
If you want to real change the discount, your code is wrong. You don’t change what discount is used when calculating the price; you just tell users that the discount is 100%, but it’s not. If extending the display method is a wrong approach, trying to fix the refresh would be a waste of time.
And I also told you what to do with the display method. Please read the blog post I linked; it’ll tell you (among other things) how to tell the system to refresh a display method when something changes in a data source. If you run into a problem, describe the problem, instead of just repeating that the refresh doesn’t work.
Hi Martin,
The link which you shared says it cannot be applied to the table methods.Scenario is,in salespool setup table ,checkbox is placed to define the sales line discount percentage.If it is marked,it show 100 ,else should perform the standard calculation.please help me to achieve this in a better way.
Hi Martin,
Currently the discount percentage (Line percent)field is in Salesline table but the logic is based on the method from Pricedisc class.
The logic of your code is flawed and you should simply stop trying to change this method. If the discount is, say, 5%, it will be 5% even if you return something else from the method. For example, if the item price is 20, the price after the discount will be 19, even if you claim that the discount is 100% or 0%. Which is a logical bug.
I didn’t notice that it’s a table method, but if using z display method was a reasonable approach (which is isn’t), you could create a form display method and put your logic there.
Hi Martin,
Yes you are right,It’s the data field from the table which is Linepercent.When I debug I noticed the values are getting populated from the display method in both salesline table and inherit the Pricedisc class. I tried to apply in the this.linepercent= _salesline.linepercent.
Can you help me where to override this logic?
I saw you previous comment,only 100 % logic is needed when the new field in enabled in the salespool table .In all other cases it should follow the standard logic Sorry for not explaining it before clearly.
I don’t think you’re right. As far as I know, the discount is taken from PriceDiscTable
, not from this display method on SalesLine
.
What values do you mean when saying “the values are getting populated from the display method” and where do you see the code? I also don’t understand what you mean by “and inherit the Pricedisc class”.
If you want to understand the standard logic, focus on PriceDisc
class. The first step is finding the right PriceDiscTable
record, because prices and discounts may be set at several levels (e.g. for a particular item and a particular customer, an item and a group of customers and so on). It uses a query created in PriceDisc.buildFindPriceDiscountQuery()
. In case of line discount percents, the value is then returned by PriceDisc_LineDisc.discPct()
. According to references, this method seems to be used to set the discount of SalesLine
(in SalesPurchLineInterface.setPriceAgreement()
, which calls SalesLineSalesPurchLine.parmLineDiscAmount()
).
Hi Martin,
Can you guide me to achieve this logic?
I am a new techie,so spent almost 2 days on this.Based on the salespoolid,the discount percent needs to be calculated,As you mentioned I had written the logic in the above method but no luck .
Sorry, I don’t have time to the whole analysis and design for you; try getting a more experienced colleague involved.
Without an analysis, I can’t really tell you what you should do. But try whether returning a different value from PriceDisc_LineDisc.discPct()
would give you the right price (I think so), and then you can think about how to get information about sales pools there, so you can use it in your extension.
pricedisc_linedisc.dispct() is not the right method. Debugger is getting triggered only for the methods salesline.discpct() and PriceDisc methods.
logic is working fine when I implement the case in salesline.discpct(),only issue is for the existing lines the linepercent is not getting reloaded. If I include the salespoolid in the update order line parameter framework I guess it should work. Since this is a simple task they asked me to dig more and complete.And that’s the reason I reached out to the user group.
It seems you’re debugging wrong logic. SalesLine.discPct()
is used when you open SalesTable
form, but that’s not the moment when the discount is determined. Prices and discounts are found in trade agreements (and other places) when you change fields that influence prices and discounts, such as ItemId
or SalesQty
.
The purpose of discount fields isn’t just showing something to users. They influence the sales amount of the order line.
If you think that I’m kidding, then you’ll never be able to implement the logic correctly. You’re current design is simply wrong.