| Quintiq file version 2.0 | 
| #parent: #root | 
| Method NewKBBranch ( | 
|   internal[KBFullID] kbfullid, | 
|   Scenario scenario | 
| ) id:Method_ApplicationLibMacroPlanner_NewKBBranch | 
| { | 
|   #keys: '[11122.0.58944168]' | 
|   Body: | 
|   [* | 
|     // Save as ... for a KnowledgeBase | 
|     saveid := kbfullid; | 
|      | 
|     dlg := construct( dlgEditKBID ); | 
|     dlg.Data( saveid ); | 
|      | 
|     if (saveid.Branch() = '' ) | 
|     { | 
|       edit := select (Domain.KnowledgeBaseDefinitions(),Elements,el,el.Name() = saveid.Name() and el.Domain().Domain() = saveid.Domain()); | 
|       dlg.EditorBranch().Text( edit.DefaultBranchName() ); | 
|       dlg.EditorVersion().Text( '1.0.0.0' ); | 
|     } | 
|      | 
|     if ( dlg.DoModal( this ) > 0 ) | 
|     { | 
|       editor := CKBEditor::Create(); | 
|       componentmds := ComponentMDS::CreateForLoadedMDSsOnly( Application ); | 
|       mdsinstance := selectobject( componentmds, ComponentMDSKinds.ComponentMDSInstances, m, m.MDSID().Equals( scenario.DatasetMDSID() ) ); | 
|       mdshandle := mdsinstance.GetMDSHandle(); | 
|      | 
|       if ( kbfullid.ChangeNr() = 0 ) | 
|       { | 
|         ckbhandle := editor.LoadMDSKB( mdshandle, kbfullid.KBID() ); | 
|         modelkb := editor.GetModelKB( kbfullid.KBID() ); | 
|         ckbhandle.CKB().Upgrade( modelkb.CKB() ); | 
|      | 
|         editor.ApplyMDSKB( mdshandle,ckbhandle, true ); | 
|       } | 
|      | 
|       editor.SaveMDSKBAs( mdshandle, saveid, 'New branch' ); | 
|       ScenarioManager.UpdateScenarioKBInfo( scenario, saveid.Name(), saveid.Branch(), saveid.ChangeNr(), scenario.State(), '' ) | 
|     } | 
|   *] | 
| } |