Quintiq file version 2.0
#parent: #root
Method RefreshData () id:Method_SC_frmScenarioCompare_RefreshData
{
  #keys: '[136398.1.957240028]'
  Accessibility: 'Extensible'
  Body:
  [*
    // Queries the KPI Tracker for the KPI compare data
    compareLabel := selKpiCompareLabel.Data();
    compareLabels := selectset( dhSelectedCompareLabelValues.Data(), Elements, val, 
                                val.Label() = compareLabel );
    
    fixedLabels := selectset( dhSelectedFilterLabelValues.Data(), Elements, val, 
                              val.Label() <> compareLabel );
    
    set := Kpi_GlobalState.QueryDataFromServer( compareLabels, fixedLabels );
    
    Kpi_GlobalState.PropagateLabel( set, compareLabel.Name() );
    Kpi_GlobalState.PropagateTimeStamp( set, rbgTimeType.BoundValue() );
    
    //Remove duplicate values and set relations
    uniquesetdatavalues := construct( Strings )
    sortedsetsnapshots := selectsortedset( set, SnapshotData, snapshot, true, DateTime::Now() - snapshot.ServerDateTime() )
    
    traverse( sortedsetsnapshots, Elements, snapshot )
    {                                               
      traverse( snapshot, Value, datavalue )
      {
        uniquestring := datavalue.Name() + ";" + datavalue.UI_LabelValue()
        if( exists( uniquesetdatavalues, Elements, value, value = uniquestring ) )
        { //remove older duplicate   
          datavalue.Delete();
        }                    
        else
        {                      
          uniquesetdatavalues.Add( uniquestring)
        }
      }
    }  
    
                            
    // Set relations
    traverse( set, SnapshotData.Value, v ) 
    {
      v.UI_CompareLabel( relset, select( compareLabels, Elements, s, s.Value() = v.UI_LabelValue() ) );
      v.UI_Kpi( relset, select( KpiTracker, MetaData, k, k.Name() = v.Name() ) );
    }  
     
    dhSnapshotData.Data( &set );
  *]
  UseInheritedAccessibility: false
}
