yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
Quintiq file version 2.0
#parent: #root
Method CreateScenarioMPFromDataset (
  ScenarioNode scenarionode,
  String scenarioname,
  String assumption,
  String comment,
  String scenariodescription,
  String datasetname,
  Key datasetmdsid,
  String datasetstoragestate
) as ScenarioMP
{
  Description: 'Create a scenario only, do not create dataset'
  TextBody:
  [*
    // Get current user's name
    currentusername := GlobalParameters_MP::GetUserName();
    
    //create a new scenario
    scenario := construct( ScenarioMP,
                           AsScenarioMP           := this,
                           Name                   := scenarioname,
                           CreatedBy              := currentusername,
                           CreatedOn              := DateTime::Now(),
                           DatasetMDSID           := datasetmdsid,
                           DatasetName            := datasetname,
                           Comment                := comment,
                           IsLoaded               := true,
                           State                  := datasetstoragestate,
                           KBDescription          := scenariodescription
                          );
    
    // Update last changed info of this scenario, which is the current user in this case
    scenario.UpdateLastChanged();
    
    // Get mds info of the selected dataset
    mdsinfo := MDSEditor::Editor().ObjectInfo( datasetmdsid );
    
    // Check if the selected dataset can be found or is it online
    if( not isnull( mdsinfo )
        // Just an extra guard to make sure dataset is loaded [ UI also block where unloaded dataset without scenario can not be created as scenario ]
        and mdsinfo.IsLoaded() )
    {
      MacroPlan::JobUpdateCompany( mdsinfo.MDSID(), scenario );
    }
    else
    {
      debuginfo( '#### mds isnull: ID = ', datasetmdsid );
    }
    
    // Add scenario to scenario manager
    scn := this.AddLeaf( scenarionode, &scenario ).astype( ScenarioMP );
    // Create assumption for the new scenario
    scn.CreateNewAssumption( assumption );
    
    return scn;
  *]
}