cancel
Showing results for 
Search instead for 
Did you mean: 

Get modified field in OnSave

former_member200925
Active Participant
0 Kudos

Hi all,

Exist one way to get or check in the event OnSave the field was changed ?

Accepted Solutions (0)

Answers (2)

Answers (2)

sunil1101
Advisor
Advisor
0 Kudos

Hi

I did not understand the question but trying to give you an answer

CheckIn on the validation OnSave only unlock the file so other user can check it out and can edit it.

or Could you elaborate your question?

Regards

Sunil

ludger_bunger
Participant
0 Kudos

Hi Anderson,

I really ought to make a blog post explaining how to detect whether a specific field has changed since the latest check since this seems to be a common requirement I also had a few times.

First: there is no support to detect the specific change just that something changed.

So you need to implement this yourself:

  1. Add a custom field "previousValue" or similar
  2. Add the following code to your AfterModify/BeforeSave to check whether the field "field" changed since last check:
    if (field != previousValue) {
      previousValue = field;
      // add your custom code here:
      // custom code
    }

Since you cannot modify the var "previousValue" in OnSave you need to do this in BeforeSave and store whether a change occured in a (possibly transient) field.

Hope to help,

Ludger

HorstSchaude
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Anderson,

There are in principle two different ways to handle this requirement:

  1. Call a query ()
    • Make sure that you call the "DataOnly" version because otherwise the BO buffer is replaced by the query result
    • Of course use the "FromDb" version of the query
  2. Track by yourself ()
    • Add transient fields for the relevant elements
    • Copy the values in the "AfterLoading" event
    • Compare the transient elements wioth the "real" ones in the "BeforeSave"

HTH,

   Horst

Former Member
0 Kudos

Hi Horst,

I thought the only possible query - which makes sure the data comes from Database - is the "ExecuteFromDB()" query. Can you confirm this?

Can't the "ExecuteDataOnly()" retrieve data from buffer?

Thanks.
Fernando

HorstSchaude
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Fernando,

It must be a "ExecuteDataOnlyFromDB".
Honestly I don't know how far the develpment is here.

Definitely not the "ExecuteDataOnly" as this retrieves from the buffer

HTH,

   Horst

former_member200925
Active Participant
0 Kudos

Hi Horst,

I extended the object "BussinessPartner" and for this objeto the event "AfterLoadiing" not exist.

I can put the Transient field, and compare in the BeforeSave, but when this field is validated in OnSave the value is not real, because the event "BeforeSave" is called many times. In the second call of event "BeforeSave" the field was changed to "not modified" because in the first execute of event the field was set to "modified".

How can I execute BeforeSave only one time or call the code only one time ?

former_member186648
Active Contributor
0 Kudos

Hi Anderson,

Transient is not allowed in XBO so AfterLoading is also not available in XBO.

Thanks, Pradeep.

HorstSchaude
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Anderson,

Ahh, very import information: You are in a Business Object Extension.

That's a different game. As Pradeep mentions, there is no Transient annotation in XBO.

As it is the Business Partner you can also not use the Node Extension.

The exit BeforeSave is executed if the Save proces is started as often  as soem data of the node has been changed. This can be influenced form the programming side.

You logic must become more stable in this situation.

Bye,

   Horst

former_member200925
Active Participant
0 Kudos

Hello Horst,

I understood what you said and I appreciate the information, but is there any way to capture the change fields extended in XBO ? or were restricted because the object is standard?

Former Member
0 Kudos

Hi Anderson,

The guys here have basically suggested you two approaches:

- Create another field for each field you want to control the changes, and manage it manually. These additional fields are not shown on UI, they are used just to manage the changes.

- Do a query from DB and compare the value coming on the instances from DB with "this". Just be careful with performance issues.

Thanks.

Fernando

HorstSchaude
Product and Topic Expert
Product and Topic Expert
0 Kudos

Exact

former_member186648
Active Contributor
0 Kudos

Hi,

I don't think there is any straight forward way to find it.

You could try the following
call Retrieve (gets data from buffer) and then

call Query(gets data from the database) on the same node
and compare the result between Retrieve and Query for the same instance if there is any difference, if yes,  which means it was modified and buffer contains the modification, so you can find the particular field that got changed.

Thanks, Pradeep.