Forum Discussion

et3ishak's avatar
et3ishak
Ideator II
6 years ago

How do I find all of the property names associated with an object definition?

I am attempting to query all of the names of the properties from the User ItemType.

Essentially, with my first AML query, I am attempting to get all of the property names that are attached to the User ItemType definition. From there I will be able to dynamically populate a table with all associated property names and values for each row. Looking for the properties surround by the red square in screen shot

Below is a Dialog window that I have created, so my connection is established prior to showing this form, I set the Public Connection property on this form, and then show it.

Below is my failed attempt

Option Strict On
Option Explicit On
Option Infer Off
Imports Aras.IOM
Imports System.Text
Public Class ArasInnovatorUsers
    Public Connection As HttpServerConnection
    Private Sub ArasInnovatorUsers_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim sb1 As New StringBuilder
        Dim sb2 As New StringBuilder
        Dim dQ As String = Chr(34) ' Double Quotes
        Dim inv As New Innovator(Connection)
        Dim UserProperties As New List(Of String)
        'sb1.AppendLine(String.Format("<AML>", ""))
        'sb1.AppendLine(String.Format("    <Item action={0}get{0} type={0}ItemType{0}>", dQ))
        'sb1.AppendLine(String.Format("        <Relationships>", ""))
        'sb1.AppendLine(String.Format("            <Item action={0}get{0} type={0}Property{0} select={0}name{0}/>", dQ))
        'sb1.AppendLine(String.Format("        </Relationships>", ""))
        'sb1.AppendLine(String.Format("    </Item>", ""))
        'sb1.AppendLine(String.Format("</AML>", ""))
        sb1.AppendLine(String.Format("<AML>", ""))
        sb1.AppendLine(String.Format("<Item type={0}ItemType{0} action={0}get{0} select={0}name{0} where={0}ItemType.name = 'User'{0}>", """"))
        sb1.AppendLine(String.Format("<Relationships>", ""))
        sb1.AppendLine(String.Format("<Item type={0}Property{0} action={0}get{0} select={0}*{0}/>", """"))
        sb1.AppendLine(String.Format("</Relationships>", ""))
        sb1.AppendLine(String.Format("</Item>", ""))
        sb1.AppendLine(String.Format("</AML>", ""))

        Dim AML1 As String = sb1.ToString
        Dim item1 As Item = inv.applyAML(AML1)
        MsgBox(item1.getItemCount)
        For i As Integer = 0 To item1.getItemCount - 1
            Dim user As Item = item1.getItemByIndex(i)
            Dim propName As String = user.getProperty("name")
            UserProperties.Add(propName)
            MsgBox(propName)
        Next
        sb2.AppendLine(String.Format("<AML>", ""))
        sb2.AppendLine(String.Format("    <Item type={0}User{0} action={0}get{0} select={0}*{0}>", dQ))
        sb2.AppendLine(String.Format("        <Relationships>", ""))
        sb2.AppendLine(String.Format("            <Item type={0}Value{0} select={0}value,label{0}/>", dQ))
        sb2.AppendLine(String.Format("        </Relationships>", ""))
        sb2.AppendLine(String.Format("    </Item>", ""))
        sb2.AppendLine(String.Format("</AML>", ""))
        ListView1.Columns.Clear()
        ListView1.Items.Clear()
        Dim AML2 As String = sb2.ToString
        Dim item2 As Item = inv.applyAML(AML2)
        For i As Integer = 0 To item2.getItemCount - 1
            Dim user As Item = item2.getItemByIndex(i)
            '   MsgBox(user.getProperty("login_name"))
        Next
    End Sub
End Class

6 Replies

  • asebastian's avatar
    asebastian
    Community Manager

    Hello,

    I quickly generated some AML which does the following. I created and tested this using nash in a local instance. You'll need to modify your VB code to create the string, but the end result should look like this:

    <AML>
    <Item action="get" type="itemType" select="name">
    <name>part</name>
    <Relationships>
    <Item type="property" action="get" select="value, label" />
    </Relationships>
    </Item>
    </AML>

    This AML will take the itemtype specified within the <name> tag and return some basic information about that ItemType, as well as all the value/label combinations for the related properties.

    AJ

    • et3ishak's avatar
      et3ishak
      Ideator II

      Thank you AJ, let me test this and get back to you!

    • et3ishak's avatar
      et3ishak
      Ideator II

      That didn't quite solve my problem, but it did get me working towards a solution which is partially successful. Now the issue is that I can get all property names, but not the labels... Newest working code below...

      I guess part of the answer I was looking for was in the fact that the resultes are embedded into the XML nodes, not that I quite understand that structure yet....

      Option Strict On
      Option Explicit On
      Option Infer Off
      Imports Aras.IOM
      Imports System.Text
      Imports System.Xml
      Public Class ArasInnovatorUsers
          Public Connection As HttpServerConnection
          Private Sub ArasInnovatorUsers_Load(sender As Object, e As EventArgs) Handles MyBase.Load
              Dim sb1 As New StringBuilder
              Dim dQ As String = Chr(34) ' Double Quotes
              Dim inv As New Innovator(Connection)
              Dim UserPropertyNames As New List(Of String)
              sb1.AppendLine("<AML>")
              sb1.AppendLine("    <Item action='get' type='User' select ='*'>")
              sb1.AppendLine("        <Relationships>")
              sb1.AppendLine("            <Item type='property' action='get' select='*'/>")
              sb1.AppendLine("        </Relationships>")
              sb1.AppendLine("    </Item>")
              sb1.Append("</AML>")
              Dim AML1 As String = sb1.ToString
              Dim aml_1 As Item = inv.applyAML(AML1)
              'Failed attempt to retrieve value, label
              MsgBox(aml_1.getItemByIndex(0).getProperty("value"))
              MsgBox(aml_1.getItemByIndex(0).getProperty("label"))
              For i As Integer = 0 To aml_1.getItemByIndex(0).node.ChildNodes.Count - 1
                  'Gets all property names, but not the label...
                  UserPropertyNames.Add(aml_1.getItemByIndex(0).node.ChildNodes(i).Name)
              Next
              lstViewArasUsers.Items.Clear()
              lstViewArasUsers.Columns.Clear()
              For Each prop As String In UserPropertyNames
                  lstViewArasUsers.Columns.Add(prop)
              Next
              For i As Integer = 0 To aml_1.getItemCount - 1
                  Dim user As Item = aml_1.getItemByIndex(i)
                  Dim item As ListViewItem = Nothing
                  For i2 As Integer = 0 To UserPropertyNames.Count - 1
                      Dim prop As String = UserPropertyNames.Item(i2)
                      Dim propValue As String = user.getProperty(prop)
                      If i2 = 0 Then
                          item = New ListViewItem(propValue)
                      Else
                          item.SubItems.Add(propValue)
                      End If
                  Next
                  lstViewArasUsers.Items.Add(item)
              Next
          End Sub
      End Class

      • asebastian's avatar
        asebastian
        Community Manager

        Could you post an example of the XML which is returned? I recommend testing the AML through nash, and then that way you can know what you'll have to parse using your code.