| Quintiq file version 2.0 | 
| #parent: #root | 
| Method NewScenario ( | 
|   internal[GUIComponent] parent, | 
|   ScenarioManager owner, | 
|   ScenarioNode scenarionode, | 
|   Boolean enableautoimport | 
| ) as Scenario id:Method_ScenarioManager_DialogCreateEditMPScenario_NewScenario | 
| { | 
|   #keys: '[11122.0.37341038]' | 
|   Body: | 
|   [* | 
|     // New scenario | 
|     this.SetAdvanced(); | 
|      | 
|     strategy := select(ScenarioManager, Strategy, strategy, strategy.Name() = Translations::MP_GlobalParameters_DefaultStrategyName() ); | 
|     if( not isnull( strategy ) ) | 
|     { | 
|       SelectionStrategy.Data( strategy ); | 
|     } | 
|      | 
|     result := this.DoModal( parent ); | 
|     scenario := null ( Scenario ); | 
|      | 
|     if ( result > 0 ) | 
|     { | 
|       scenario := owner.CreateScenarioMP( scenarionode, | 
|                                           EditorScenarioName.Text(), | 
|                                           EditorAssumption.Text(), | 
|                                           EditorComment.Text(), | 
|                                           RadioButtonGroupStorageState.BoundValue(), | 
|                                           '', | 
|                                           guard( SWF_DataHolderCurrentUser.Data().Name(), '' ) ); | 
|      | 
|       kbfullid := SelectionKBBranch.Data(); | 
|       if ( RadioButtonGroupMode.BoundValue() = GlobalParameters_MP::GetKB_New() ) | 
|       { | 
|         this.InstantiateAndSelectKB( scenario ); | 
|       } | 
|       else if ( RadioButtonGroupMode.BoundValue() = GlobalParameters_MP::GetKB_CreateCopy() ) | 
|       { | 
|         this.CopyAndSelectKB( SelectionKBBranch.Data(), scenario ); | 
|       } | 
|       else | 
|       { | 
|         ApplicationLibMacroPlanner.SelectKB( scenario, kbfullid ); | 
|       } | 
|        | 
|       if( not isnull( SelectionStrategy.Data() ) ) | 
|       { | 
|         scenario.SelectedStrategy( relset, SelectionStrategy.Data() ); | 
|       } | 
|        | 
|       // Set user preference on supply chain wizard launch | 
|       owner.LaunchInitializationWizardAtScenarioCreation( Dialog.CheckBoxLaunchSupplyChainWizard().Checked() ); | 
|        | 
|     } | 
|      | 
|     isselected := ApplicationLibMacroPlanner.SelectScenario( scenario ); | 
|     if ( isselected ) | 
|     { | 
|       /* Is important to set active dataset on FormScenario. | 
|          Without setting it, the auto import will import data to the previous scenario instead of the new one. | 
|          This happend because some propagation in Quintiq it not yet done while we fire the import method. | 
|       */ | 
|       ApplicationLibMacroPlanner.SelectScenario( scenario, this ); | 
|      | 
|       ApplicationLibMacroPlanner.SupplyChainDiagramSetSupplyChainView( MacroPlan ); | 
|       if ( not isnull( DataHolderView.Data() ) ) | 
|       { | 
|         feedback := '' | 
|         DataHolderView.Data().RestoreDefaultLayout( feedback ); | 
|       } | 
|     } | 
|      | 
|     return scenario; | 
|   *] | 
| } |