| Quintiq file version 2.0 | 
| #parent: #root | 
| Method Execute_DataMigration_NonFinancialKPI ( | 
|   String oldname, | 
|   String newname | 
| ) | 
| { | 
|   Description: 'Generic data migration method for NonFinancialKPI' | 
|   TextBody: | 
|   [* | 
|     oldkpi := KPI::FindKPITypeIndex( oldname ); | 
|     newkpi := KPI::FindKPITypeIndex( newname ); | 
|     newkpitable := NonFinancialKPITable::Table(); | 
|     newkpitablerow := select( newkpitable, Rows, row, row.Name() = newname ); | 
|     needsnewkpi := isnull( newkpi ) and not isnull( newkpitablerow ); | 
|     hasdatamigration := needsnewkpi and not isnull( oldkpi ); | 
|      | 
|     // can't use ChangeKeyTypeIndex as KPI has subclasses, so create new, delete old | 
|     if( needsnewkpi ) | 
|     { | 
|       newkpi := NonFinancialKPI::Create( this, | 
|                                          newname, | 
|                                          newkpitablerow.IsShown(), | 
|                                          newkpitablerow.IsPercentage(), | 
|                                          hasdatamigration /* if migration, prevents creation of kpiweight,etc as we will re-assign from old kpi to this new KPI as owner */ | 
|                                        ); | 
|      | 
|      | 
|       if( hasdatamigration ) | 
|       {  | 
|         oldkpi.IsMigratingData( true ); // Prevents cleanup as we want to re-assign kpiweight,etc to new KPI (owner) | 
|          | 
|         traverse( oldkpi, KPIValue, kpivalue ) | 
|         { | 
|           newkpi.KPIValue( relinsert, kpivalue );  | 
|         } | 
|          | 
|         traverse( oldkpi, KPIWeight, kpiweight ) | 
|         { | 
|           KPIWeight::ChangeKeyKPIWeightTypeIndex( kpiweight, newname, kpiweight.StrategyName() ); | 
|         } | 
|          | 
|         kpisetting := oldkpi.KPISetting(); | 
|         if( not( isnull( kpisetting ) ) ) | 
|         { | 
|           KPISetting::ChangeKeyKPISettingTypeIndex( kpisetting, newname );  | 
|           newkpi.KPISetting( relmove, kpisetting ); | 
|         }   | 
|          | 
|         newkpi.IsMigratingData( false ); // Reset migration status once we done owning those objects from old KPI | 
|          | 
|         oldkpi.Delete(); | 
|       } | 
|     } | 
|   *] | 
|   InterfaceProperties { Accessibility: 'Module' } | 
| } |