I want to create a CRMScript trigger which calculates discount and discount percent after saving a product in Quote.
I can observe that the calculated values are saved only if the user actually edits the discount. (Else it is always set to 0. 0%)
Trigger (Sales: After saving in dialog Add/edit product)
EventData ed = getEventData();
Integer quantity = ed.getInputValue("QuoteLine.Quantity").toInteger();
Float MRR = ed.getInputValue("QuoteLine.ExtraField4").toFloat();
Float listPrice = ed.getInputValue("QuoteLine.UnitListPrice").toFloat();
Float sum = ed.getInputValue("QuoteLine.SubTotal").toFloat();
// Calculate discount, percentage
Float discount = (listPrice * quantity) - (MRR * quantity);
Float discountPercentage = discount / sum * 100;
Integer id = ed.getInputValue("QuoteLine.QuoteLineId").toInteger();
NSQuoteLine line = agent.GetQuoteLine(id);
line = agent.SaveQuoteLine(line);
I'm guessing my code is missing something, but I can't figure out what. Perhaps it has something to do with this method? Or a rule or setting I have to change somewhere?
Any help is much appreciated.