Notifications
Announcements
No record found.
Hi Experts,I have a requirement . If user change the Sales Price in Sales Line then a Dialog open and user select the Reason Code .After that My SalesLine data will get saved in Custom History Table.So I need to save the OriginalPrice(Previous Value which got changed) and Updated Price(New Value) in History Table.
How Can I achive this -
I used - salesLine.orig().SalesPrice
But it is saving the Original Value of Sales Price field every time I update that field for a particular record.
Hi, I think you will get orig value before table is updated. How about creating CoC on update method of SalesLine table and capturing the values before and after next call and update Custom History Table.
Hi Harish,
Can you be more precise what you mean with "update that field for a particular record."? What x++ coding did you use and on what place did you put that coding?
Hi,Writing code in OnModified form control.
[FormControlEventHandler(formControlStr(SalesTable, SalesLine_SalesPrice), FormControlEventType::Modified)] public static void SalesLine_SalesPrice_OnModified(FormControl sender, FormControlEventArgs e) { FormDataSource salesLine_ds = sender.formRun().dataSource("SalesLine"); SalesLine salesLine = salesLine_ds.cursor(); ReasonMain_CAP reason_Cap; PriceChangeHistory_CAP priceChangeHistory; Dialog dialog; Dialog dlg = new Dialog('@CAP:DialogCaptionInDialogSalesPrice'); DialogField dfReasonCode = dlg.addField(extendedTypeStr(ReasonCode_CAP),'ReasonCode'); if(dlg.run()) if (dfReasonCode.value() != '' ) { ttsbegin; dlg.closedOk(); priceChangeHistory.ReasonCode = dfReasonCode.value(); priceChangeHistory.CurrencyCode = salesLine.CurrencyCode; priceChangeHistory.OrderNumber = salesLine.SalesId; priceChangeHistory.ItemNumber = salesLine.ItemId; priceChangeHistory.LineNum = salesLine.LineNum; priceChangeHistory.OriginalPrice = salesLine.orig().SalesPrice; priceChangeHistory.UpdatedPrice = salesLine.SalesPrice; priceChangeHistory.ReferenceType = '@CAP:SalesOrder'; priceChangeHistory.CreateDateTime = today(); priceChangeHistory.RecIDSales = salesLine.RecId; priceChangeHistory.TableIDSales = salesLine.TableId; priceChangeHistory.RecIDPriceChange = priceChangeHistory.RecIDPriceChange 1 ; priceChangeHistory.CreateBy = curUserId(); priceChangeHistory.insert(); ttscommit; } else { salesLine.SalesPrice = salesLine.orig().SalesPrice; Error('Please fill the reason code'); }
If I understand it correctly, you're getting the original value of the field (before you started changing the record), but you don't want it. You want the previous value of the field, regardless of saving.
For example:
The result is:
I wonder if this is really what you want. I would guess that your actual intention was saving information about price change of an order line that was actually saved.
Hi Martin,
Yes as per this scenario I want the record to save in PriceChangeHistory Table like this scenario-
1.You have a record with price 1 and start editing it.
2.You change the price to two, which creates PriceChangeHistory record with OriginalPrice = 1 and UpdatedPrice = 2.
3.Then you change the price to five, which creates a PriceChangeHistory record with OriginalPrice = 2 and UpdatedPrice = 5.
4.Again then OriginalPrice =5 and UpdatedPrice =9 and after updating price a dialog will open and If user cancel the dialog then no record is created on PriceChangeHistory Table and the Updated Value reverse back to OriginalPrice that is 5 in SalesPrice.
But what is happening in my case is when I am using salesLine.orig().SalesPrice for storing the previous value, It is saving OriginalPrice as 1 all the time.
I understand what you're saying, but it's missing my point.
Could you please confirm that your PriceChangeHistory table should store price changes that were never saved to SalesLine table? It's how your current implementation works, but it sounds strange. I suspect it's a bug in your overall design.
Yes, the original price is 1 in all cases. With your current design, you want the previous values of the field of the buffer, not the original values with which the record was loaded from database. But it's possible that the original value is what you'll need in the correct solution.
Yes. PriceChangeHistory table will store the Price change which were never saved in SalesLine table. This PriceChangeHistory table is to store the reason for which price is changed and what is the price that is changed.
But if the change isn't saved, no change occurred. Therefore the history will store information about change (e.g. that the price was changed from 10 to 15 and why), although the price didn't change. The history would claim that price changed to 15, which is a lie - it's still 10 and it always was.
What business problem is solved by a change history table with these misleading entries?
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Martin Dráb 664 Most Valuable Professional
André Arnaud de Cal... 522 Super User 2025 Season 2
Sohaib Cheema 303 User Group Leader