5 Replies Latest reply on Oct 27, 2012 7:05 AM by aabrodskiy

    AFElement.LoadElementsToDepth returns a list missing a given element

    jason.maxwell

      I am making use of the AFElement.LoadElementsToDepth call to return a full list of all elements in the current AF database.  I am trying to use this full list of elements to determine if a new element needs to be created during a creation process.   After getting the full list of elements I search it using the .contains(string name) method.  If the element in question is not found, create it and add it to the database.  Since the element exists but is not returned by the LoadElementsToDepth function, a new element is created and added to the root element list, but an exception is thrown that another element with the same name already exists.

       

      This is the snippet of code that performs the list creation:

       
      private AFDatabase currentDatabase;
      
      private AFNamedCollection flatElementList;
      
      private void AFGetElements()
              {
                  List templist = new List();
                  foreach (AFElement element in currentDatabase.Elements)
                  {
                      templist.Add(element);
                  }
                  flatElementList = AFElement.LoadElementsToDepth(templist, false, int.MaxValue, int.MaxValue);
              }
      

      The issue I am having is that one of the root elements that is set as part of the search list does not end up in the returned collection.

       

       

       

      Anyone have any thoughts on why this might happen?

       

      an example:
      root
          ->Element1
                  ->ChildOfElement1
          ->Element2 
                  ->ChildOfElement2
          ->Element3 
                  ->ChildOfElement3
       
      the templist would have 3 elements, and the LoadElementsToDepth should have 6 total elements and flatElementList.Contains("Element3") should return true but instead it returns false. 

       

       

       

      Some extra information:
      AFSDK version: 2.3.1.4095
      The element in question was created previously by the same process.

       

       

        • Re: AFElement.LoadElementsToDepth returns a list missing a given element

          When you say the same process earlier created the element I assume you checked it in before calling LoadElementsToDepth?

            • Re: AFElement.LoadElementsToDepth returns a list missing a given element
              jason.maxwell

              Yes, I use a method to check in the changes after creating all of the new elements.  The check in code looks like:

               

               

               
              public void CheckInChanges()
                      {
                          currentDatabase.CheckIn();
                          currentAFSystem.CheckIn();
                      }
              

               

               

              The call to create the list only happens at the start of any creation process.  The check in happens at the end.  There is one check in for every create process.

               

              In further investigation of the AFElement.LoadElementsToDepth it appears as if the LoadElementsToDepth only returns the children of the given element list but not the given elements themselves.

               

              I altered the flatElementList creation to check for all of the starting list and found that none of the starting list items, were contained in the result.

               

              here is the altered code:

               
              private void AFGetElements()
                      {
                          List templist = new List();
                          foreach (AFElement element in currentDatabase.Elements)
                          {
                              Logging.log.Debug("RootElement in AF Tree: " + element.Name);
                              templist.Add(element);
                          }
                          flatElementList = AFElement.LoadElementsToDepth(templist, false, int.MaxValue, int.MaxValue);
                          foreach (AFElement element in currentDatabase.Elements)
                          {
                              if (flatElementList.Contains(element))
                              {
                                  Logging.log.Debug("FlatElementList contains Root Element: " + element.Name);
                              }
                          }
                      }
              

               

               

              This behavior is different from how the documentation describes what the proceedure should be doing.  From the documentation:

               

              "Loads the specified list AFElement objects, and their children, from the server into the client. This will significantly decrease load time for loading a portion of the element hierarchy." 

               

              When in turn it appears to only load the children.  If I am missing something could someone please show me it?

               

              Thanks in advance.