Quintiq file version 2.0
#parent: #root
Method CleanKB () id:Method_ApplicationLibMacroPlanner_CleanKB
{
  #keys: '[11660.0.318162580]'
  Body:
  [*
    // Clean up KB
    editor := CKBEditor::Create();
    
    //Check if macroplan dataset is selected, if not, don't clean KB
    if( not isnull( MacroPlan ) )
    {
      kb := select( MacroPlan.MDSMacroPlan(), MDSKBs, kb, kb.Name().ToUpper() = ScenarioManager.CompanyKBName().ToUpper() );
      kbfullid := KBFullID::Create( kb.Domain(), kb.Name(), kb.Branch(), kb.Version(), kb.ChangeNr() );
    
      infos := editor.GetKBStructure( kbfullid.KBID() );
      traverse( infos, Elements.KBFullID, i )
      {
        editor.DeleteAllButLatestKBChange( i );
      }
    }
  *]
}
