Skip to Content

compare changed values in onSave event

Dear Experts,

I have a requirement to compare if a field of an Opportunity has been changed in the onSave event.

I already found a post that suggests to use FromDB Query but this does also not work. (

Please see my example:

var query = Opportunity.QueryByElements;
var selParameter = query.CreateSelectionParams();
    selParameter.Add(query.ID.content, "I", "EQ", ls_this.ID.content);
var result = query.ExecuteFromDB(selParameter); 
foreach (var ls_result in result){
var eins1 = ls_result.SalesAndServiceBusinessArea.SalesTerritoryID.content;
var zwei2 = ls_this.SalesAndServiceBusinessArea.SalesTerritoryID.content;
var eins = ls_result.Name;
var zwei = ls_this.Name; 

For vars eins1 and zwei2 the values always match, so the change in to noticed.

However for vars eins and zwei it works perfectly.

I suspect this problem occurs, as the SalesTerritoryID is part of the SalesAndServiceBusinessArea node and not the Root node.

Does anyone of you have an idea how to resolve this? Is there anyway to get the DB values of the subnodes?

Thanks for your help

Best Regards

Tobias Träger

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Jan 11, 2018 at 03:45 PM

    Hi Tobias,

    I also had the same issue as you, I solved it like this:
    I created a custom fields for old value (Old_Value) and bind it to related value and in the Event After Modify you can compare "this.Value" with "this.Old_Value" (since Old_Vlaue still has the previous value not the new one)

    Hope it can help


    Add comment
    10|10000 characters needed characters exceeded

  • Jan 04, 2018 at 05:04 PM

    Hi Tobias,

    As an quick idea, have already tried to created an validation on save script at the node SalesAndServiceBusinessArea and checked what there are the results?


    As an anticipation from my side (not really sure if this is right), it could be because the part "ls_result.SalesAndServiceBusinessArea" resolves an association and I'm not sure if this is also an DB only resolution or from the buffer. As mentioned in the documentation the ExecuteFromDB returns the data from the DB not from the buffer, but the behavior of the association resolution is not directly specified. Its more or less the expected behavior...

    ExecuteFromDB Function
    The ExecuteFromDB function provides the same parameters for selection and sorting as the Execute function. However,ExecuteFromDB function returns the data that is saved on the Database and not from the buffer. Hence, the data returned via this function will not contain any unsaved changes done in the current transaction.

    Best regards

    Tobias Kuhn

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 05, 2018 at 12:49 PM

    Hi Tobias,

    thanks for your reply. The Validation script does not really help, as we want to save additional data in the onsave script itself. But just in case the Territory ID has changed from "something" to a "specific" territory. Due to performance reasons this routine should only be processed in detail if this condition matches.

    Like you pointed out the Query gets the result from the DB as vars eins and zwei proof.

    Unfortunely I fear that it's like you think... the root node is retrieved from the DB but the associations come from the buffer. which is unexpected behavior in my opinion, as I told the query to use the DB. Can anyone from SAP proof this Theory?

    So the question at the end is: is there any possibility to get those associations/sub nodes/compositions also from the DB instead of the buffer? Because as far as I know this sub-notes in the example can only be accessed by a association, there are no queries etc. definable.

    Best Regards


    Add comment
    10|10000 characters needed characters exceeded