# Handling Changes
source: https://developer.mastercard.com/open-finance-europe/documentation/licensed/aiia-enterprise/accounts/handling-changes/index.md

It is important to ensure all data is correct and complete when you update. You must make sure there are no duplicates or missing transactions.

To do this, we recommend that you fetch data at least seven days prior to the latest transaction. You must compare the new transactions with the transactions you already have, as providers do change and/or remove transactions at their end. If some transactions from a previous update have been removed in the new list of transactions, you must also remove them at your end.

#### Transaction states {#transaction-states}

A transaction can have one of the following states:

* `Booked` -- A transaction that has been fully processed by the bank
* `Reserved` -- A transaction that reserves an amount of currency
* `Scheduled` -- A transaction that will be processed at a specified date

If you use `Reserved` or `Scheduled` transactions, be aware that these transactions will change when the transaction is booked.

You may have an instance where you have two transaction lists with data for the same period of time.

Follow these steps to get a consistent data set:

* If a transaction exists in both the new and the existing list, update the existing one with the newer data.
* If a transaction in the new list is not in the existing list, create it.
* If a transaction in the existing list is not in the new list, delete it.

Note: **Important**   
When a transaction changes state, it will most likely get a new `id`.

#### Example {#example}

For example, a reserved transaction is removed and a new booked transaction is created with a different ID:

* Remove the reserved transaction because you can no longer see its ID in the list of transactions.

<br />

##### Create or merge an existing transaction {#create-or-merge-an-existing-transaction}

When you synchronize and get new transactions from the API, check for duplicates by comparing the `ids` of the new transactions with the transactions you already have.

```js
// List with new transactions from a given date until now
let newTransactionList = [...]

// List with all existing transactions for the same timespan
let oldTransactionList = [...]

for (var oldTransaction in oldTransactionList) {
  for (var newTransaction in newTransactionList) {
    if (oldTransaction.id === newTransaction.id) {
      update(oldTransaction, newTransaction)) 
    } else {
      create(newTransaction)
    }
  }
}
```

The list with new transactions is obtained by following the [Transactions](https://developer.mastercard.com/open-finance-europe/documentation/licensed/aiia-enterprise/accounts/transactions/index.md) guide.

##### Remove deleted transactions {#remove-deleted-transactions}

```js
// List with new transactions from a given date until now
let newTransactionList = [...]

// List with all existing transactions for the same timespan
let oldTransactionList = [...]

for (var oldTransaction in oldTransactionList) {
  // compare transaction ids
  if (!newTransactionList.includes(oldTransaction)) {
    remove(oldTransaction) 
  }
}
```

Note: Some providers might return fewer transactions than requested. The timespan chosen for the duplication handling must not start before the last transaction received from the provider.
