1 Reply Latest reply on May 12, 2010 10:39 AM by hanyong

    Assign AFReferenceType when adding new element

    Anwar005

       

       

      Hi,

       

      I want to add AFReferenceType when I add new element into AF.

       

      For Example I have added an element , F001 , into the following path \\MUS-AS-167\PDO\Wells

       

      Now I want to add reference element to the following path \\MUS-AS-167\PDO\PDO\NORTH\FAHUD\FAHUD

       

      Is it possible to achieve using AFReferenceType? Please send code sample.

       

      Thanks

       

      Anwar

        • Re: Assign AFReferenceType when adding new element
          hanyong

          Hi Anwar,

           

          I am not sure what you mean by "reference element" here. I assume you want to reference or link the same element on mulitple paths. If you attempt to add an existing element to another path in the same database, AF will create an link to the existing element in the new path.

           

          So assuming the F001 has been created under the path "\\MUS-AS-167\PDO\Wells" and you load the element and add it as a child element to FAHUD. You should see F001 added under FAHUD, and the icon will indicate it is a "shortcut" to the element. It is like multiple path leading to the same element.

           

          AFReferenceType defines the relationship between the parent element and the child element (the hierachical relationship) instead of the relationship between the same element in different path. You can look at more of this in AF help (In PI System Explorer, go to "Help -> Help Topics") in the topic "Creating Element References".

           

          If I understood what you want to do correctly, then AFReferenceType should not affect what you want to do here. Except that you might want to specify the AFReferenceType when you add the element to the new path

           

          That said adding an existing element to a new path is simple:

          ' Get the element F001, you can use other methods to do this
          Dim oElement As AFElement = myAFDB.Elements("\PDO\Wells\F001")
          ' Get the parent element to add F001 to
          Dim oParent As AFElement = myAFDB.Elements("\PDO\PDO\NORTH\FAHUD")
          ' Add the element to the new path, reference type between F001 and FAHUD is default "Parent-Child"
          oParent.Elements.Add(oElement)
          ' Add the element to the new path, specifying the reference type
          'oParent.Elements.Add(oElement, myAFDB.ReferenceTypes("Composition"))