# FM3 - calculate a field value during upgrade based on field being removed

**URL:** <https://clarionhub.com/t/fm3-calculate-a-field-value-during-upgrade-based-on-field-being-removed/7273>\
**Category:** questions\
**Tags:** fm3\
**Created:** [June 25, 2024, 3:48pm UTC](https://clarionhub.com/t/fm3-calculate-a-field-value-during-upgrade-based-on-field-being-removed/7273 "2024-06-25T15:48:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![greg](https://clarionhub.com/user_avatar/clarionhub.com/greg/32/2771_2.png) [@greg](https://clarionhub.com/u/greg)\
**Post date:** [June 25, 2024, 3:48pm UTC](https://clarionhub.com/t/fm3-calculate-a-field-value-during-upgrade-based-on-field-being-removed/7273/1 "2024-06-25T15:48:51Z")

</div>

I'm looking for a way to automaticaly fill new field values in a table from another field I'm planning to remove.  
In my Cars table version 4 I have a field EngineType STRING(1) with values B for Benzin/Petrol/Gasoline , D for Diesel, L for LPG. I am about to remove that field  
In version 5 table I want to have a new field FuelType STRING(3) with values P for Benzin/Petrol/Gasoline , D for Diesel, LPG for LPG, H for hydrogen etc. to match goverment standard.

I'm thinking of executing something like this in callback procedure when upgrading from version 4 to version 5

```
case pFunction
    of FM3equ:UpgradingFile !About to upgrade a file

    of FM3equ:CopyingRecord !After copy record, before save

		if pOptions = address(Cars) and UFD:FromVersionNumber = 4 AND |
 UFD:ToVersionNumber = 5 THEN
			 CASE CarsVer4:EngineType
			 OF 'B'
				CarsVer5:FuelType = 'P'
			 OF 'D'
				CarsVer5:FuelType = 'D'
			 OF 'L'
				CarsVer5:FuelType = 'LPG'
			 END	
    of FM3equ:UpgradingFileDetailsString
! UFDGroup = pFileName
! message('File ' & UFD:FromLabel & ' upgrading from: ' & UFD:FromPrefix & ' To: ' & UFD:ToPrefix & '|Version: ' & UFD:FromVersionNumber & ' To: ' & UFD:ToVersionNumber)
    of FM3equ:EndUpgradeFile
! message('Finished upgrading file: ' & pFileName)
    end
```

but not sure how I can refer to a field with specific table version ( CarsVer5:FuelType is just something I made up ) , also when FM3 uprades a table from say version 1 to version 6 is it going through all versions or just straight to ver 6

In this FAQ [CapeSoft File Manager 3 Complete Documentation](https://www.capesoft.com/docs/fm3/fm3.htm#FAQGQ34) there is an example how to calculate new field value but it does not show how to refer to a field that was removed in newer table version. Is that at all possible?

---

<div class="post-metadata">

**Author:** ![Bruce](https://clarionhub.com/letter_avatar_proxy/v4/letter/b/ccd318/32.png) [@Bruce](https://clarionhub.com/u/Bruce)\
**Post date:** [June 25, 2024, 7:16pm UTC](https://clarionhub.com/t/fm3-calculate-a-field-value-during-upgrade-based-on-field-being-removed/7273/2 "2024-06-25T19:16:31Z")

</div>

If it goes from version 1 to 6 it does so in one jump.

Personally i think this is a situation where you shoukd just add a new field, and leave the old field in the table for now. Populate the new field (via a process or whatever) and remove the old field at sone point in the future.

---

<div class="post-metadata">

**Author:** ![Graeme](https://clarionhub.com/letter_avatar_proxy/v4/letter/g/50afbb/32.png) [@Graeme](https://clarionhub.com/u/Graeme)\
**Post date:** [July 3, 2024, 7:52am UTC](https://clarionhub.com/t/fm3-calculate-a-field-value-during-upgrade-based-on-field-being-removed/7273/3 "2024-07-03T07:52:26Z")

</div>

I have done what Bruce recommends many times over the last 20 years. For some I have just had FM3 create the new field and done the calculation via a process at time of upgrade. Just hiding the old fields so no one knows they are even there.
