Quintiq file version 2.0 
 | 
#parent: #root 
 | 
MethodOverride Copy ( 
 | 
  ScenarioNode scenarionode, 
 | 
  String scenarioname, 
 | 
  String newassumption, 
 | 
  String comment, 
 | 
  String storagestate, 
 | 
  String kbdescription, 
 | 
  String kbname, 
 | 
  Key macroplanmdskey, 
 | 
  String datasetname 
 | 
) as Scenario 
 | 
{ 
 | 
  Description: 'Make a copy of this scenario' 
 | 
  TextBody: 
 | 
  [* 
 | 
    // Get current user's name 
 | 
    currentusername := GlobalParameters_MP::GetUserName(); 
 | 
     
 | 
    // Get mds info of the selected dataset 
 | 
    mdsEditor       := MDSEditor::Editor(); 
 | 
    mdsObjectInfo   := mdsEditor.LoadedObjectInfo( macroplanmdskey ); 
 | 
     
 | 
    //create a new scenario 
 | 
    scenario := construct( ScenarioMP, 
 | 
                           Name                    := scenarioname, 
 | 
                           CreatedBy               := currentusername, 
 | 
                           CreatedOn               := DateTime::Now(), 
 | 
                           DatasetMDSID            := macroplanmdskey, 
 | 
                           DatasetName             := datasetname, 
 | 
                           Comment                 := comment, 
 | 
                           IsLoaded                := true, 
 | 
                           KBName                  := kbname, 
 | 
                           State                   := storagestate, 
 | 
                           KBDescription           := kbdescription 
 | 
                         ); 
 | 
     
 | 
    // Copy all assumptions over from the current scenario to the new scenario 
 | 
    traverse( this, Assumption, assumption ) 
 | 
    { 
 | 
     assumption.Copy( scenario ); 
 | 
    } 
 | 
     
 | 
    // Create new assumption for the new scenario 
 | 
    scenario.CreateNewAssumption( newassumption ); 
 | 
    // Update last changed status of the new scenario 
 | 
    scenario.UpdateLastChanged(); 
 | 
    // Call job to update MacroPlan dataset with the info from the new scenario 
 | 
    MacroPlan::JobUpdateCompany( mdsObjectInfo.MDSID(), scenario ); 
 | 
     
 | 
    //Copy authorization 
 | 
    groupnames := selectvalues( this, ScenarioAuthorization, sa, true, sa.Name() ) 
 | 
    scenario.Authorize( groupnames, true ); 
 | 
     
 | 
    // refresh KPI after copy 
 | 
    /*Create MDSID from ScenarioManager, then pass the arguments 
 | 
      to existing method to refresh newly copied scenario KPI*/ 
 | 
    smMDSID := MDSID::Create( this.ScenarioManager().MDSID() ); 
 | 
    ScenarioManager::JobUpdateKPIValue( smMDSID, false, mdsObjectInfo.MDSID() ) 
 | 
     
 | 
    // Add the new scenario into scenario manager 
 | 
    return this.ScenarioManager().AddLeaf( scenarionode, &scenario ).astype( Scenario ); 
 | 
  *] 
 | 
} 
 |