Change of one record based on another

Hi everyone,

I’m quite novel to this technology. I had a problem that on change of some y field in one record should lead to change of x field in previous record.

Can anyone suggest me how can I do this?

Many Greetings,


It would be too early to update another record immediately when a field changes, because the current record is not saved yet. What you usually want is to update the other record in the same transaction as the update (potentially insert and delete too) of the source record. You can use update() method on the table for that.

To identify whether a field changes, use this.orig() method in update() to get original values and check whether your field has changed.

You’ll also have to define the “previous” record more precisely, to be able to write a query to find the record and update it.

This is not the only possible interpretation of what you wrote, but it’s by far the most common approach.

Hi… I tried with this method… but could not update the new record.

The thing is I have fromDate in record2. When this record is approved (that means saved), then automatically the toDate must be (system date - 1day = previous day) in record1.

can any one help me out to solve this issue?

If your version is 2012, you should definitely look for the date effective patterns.

I still don’t follow exactly what you need. I’ll assume something and you can adjust details to what you really need (and please, try to describe the problem in better details next time). I’ll completely ignore the (system date - 1day = previous day) expression, because it simply says that (previous day = yesterday). I have also no idea what could not update the new record means.

I assume that when you create a record, you want to update ToDate field of an existing record with the highest ToDate to the value calculated from the record being saved. The value would be FromDate - 1.

So, you need few simple steps:

  1. Create a new table method to do the update, e.g. updateToDate().
    1. Find the record to be updated. If you use my definition, you would find the record with highest ToDate (select firstOnly order by). If you want to use this method even when the current record already exists, exclude it from the search (RecId != this.RecId).
    2. Set the value (this.FromDate -1)
    3. Save the record (update())
  2. Call the new method In insert(). Add a transaction covering both the new call and super().

If I missed what you really want, please start from beginning and describe what you want and what is the problem. I did all what I can with current information.

Hi, Thanks a lot for the information. I somehow get the values for that particular field. I can the value when I use debugger. But I cannot see the field value on the main form where I want to see. How can I get the values on the form?