Quintiq file version 2.0
#parent: #root
Method SelectScenarioReadOnly (
  Scenario scenario
) as Boolean id:Method_ApplicationLibMacroPlanner_SelectScenarioReadOnly
{
  #keys: '[144528.3.487223653]'
  Body:
  [*
    // Select the active MacroPlan based on passed in scenario
    // Set active MacroPlan to the application
    // ComponentMDS::Create( Application ) is not available in Editor -- still finding, if exist, all this code will be moved.
    status := false;
    
    if( not isnull( scenario ) )
    {
      loop := true;
      p := Progress::Level( 'Loading scenario...', 10 );
    
      // changed the operation in "p.Current() < p.Maximum()" from <= to < as p.Maximum will never be reached
      // causing an infinite loop when a dataset is no longer available
      while( loop and p.Current() < p.Maximum() )
      {
        componentmds := ComponentMDS::CreateForLoadedMDSsOnly( Application );
        mdsinstance := select( componentmds, ComponentMDSKinds.ComponentMDSInstances, m, m.MDSID().MDSKey() = scenario.DatasetMDSID() );
    
        if( not isnull( mdsinstance ) )
        {
          mdsinstance.ComponentMDSKind().SelectInstance( mdsinstance );
          componentmds.Apply();
          // To set the data holder if only a scenario has changed.
          if( DataHolderActiveScenario.Data() <> scenario )
          {
            DataHolderActiveScenario.Data( scenario );
          }
          status := true;
          loop := false;
        }
        p.Increment();
      }
    }
    
    return status;
  *]
}
