Quintiq file version 2.0
#parent: #root
Method InstantiateAndSelectKB (
  Scenario scenario
) as internal[KBFullID] id:Method_ScenarioManager_DialogCreateEditMPScenario_InstantiateAndSelectKB
{
  #keys: '[11660.0.806122670]'
  Body:
  [*
    //Instantiate knowledge
    Domain.PublishKnowledge();
    editor := CKBEditor::Create();
    kbfullid := maxselect ( DataHolderKB.Data(), Elements.KBFullID, k, k.Name().ToUpper() = ScenarioManager.CompanyKBName().ToUpper(), k.ChangeNr() );
    ids := editor.GetKBs();
    mid := selectobject (ids, Elements, e, e.Domain() = kbfullid.Domain() and e.Name() = kbfullid.Name(), true)
    modelkb := editor.GetModelKB( mid );
    
    //get a copy so we could edit
    saveid := modelkb.CKB().ID();
    saveid.Version( "1.0.0.0" );
    saveid.Branch( EditorBranch.Text() );
    
    //Perform the actual saveAs action
    editor.SaveKBAs( modelkb, modelkb.CKB().ID(), '');
    saveid.ChangeNr( 1 );
    
    //Select the new KB for the MDS
    ApplicationLibMacroPlanner.SelectKB( scenario, saveid );
    
    return saveid;
  *]
}
