Quintiq file version 2.0
#parent: #root
Method CopyAndSelectKB (
  internal[KBFullID] kbfullid,
  Scenario scenario
) id:Method_ScenarioManager_DialogCreateEditMPScenario_CopyAndSelectKB
{
  #keys: '[11660.0.795884786]'
  Body:
  [*
    //Instantiate knowledge
    Domain.PublishKnowledge();
    editor := CKBEditor::Create();
    modelkb := editor.GetModelKB( kbfullid.KBID() );
    
    //get a copy so we could edit
    saveid := KBFullID::Create( kbfullid.Domain(), kbfullid.Name(), kbfullid.Branch(), kbfullid.Version() );
    saveid.Version( "1.0.0.0" );
    saveid.Branch( EditorBranch.Text() );
    
    //Perform the upgrade if needed
    ckbhandle := editor.LoadKB( kbfullid );
    ckbhandle.CKB().ValidateAll();
    ckbhandle.CKB().Upgrade( modelkb.CKB() );
    
    //Perform the actual saveAs action
    newkb := editor.SaveKBAs( ckbhandle, saveid, '');
    
    //Select the new KB for the MDS
    ApplicationLibMacroPlanner.SelectKB( scenario, newkb );
  *]
}
