Community
Showing results for 
Search instead for 
Do you mean 
Reply

Accessing a field

New Member
Posts: 1
Country: Australia

Accessing a field

Hi, I am accessing a field from the Contact using the following code:

stest = contact.Fields["Registry Category", false].ToString();

I have tried

stest = contact.Fields["Registry Category", true].ToString();

The problem is the field is not found. I have looked in the layout editor and the field is certainly labelled "Registry Category".

 

I have tried listing all of the fields using the ContactFieldDescriptor type for the contact.Fields collection. This is a problem for multiple fields but not all.

 

Can anyone let me know what I am doing wrong.....


Regards


Greg

 

Administrator
Posts: 3,141
Country: United_Kingdom

Re: Accessing a field

[ Edited ]

Hi Greg,

What are you using to access the database? What type of code is this?

I've moved this thread to the Developers Lounge for more relevant exposure.

Nickel Contributor
Posts: 165
Country: USA

Re: Accessing a field

That looks like C#, so my example below (vb.net) may not be the best for you, but I still think it'll help out with the flow of things. One of the issues I've been exposed to in my not so deep knowledge of the ACT SDKs is that the most defined field descriptors generally don't work (i.e. ContactFieldDescriptor, CompanyFieldDescriptor, etc.). You have to go a level lower, which is the MutableEntityFieldDescriptor.

 

Below is a routine (not 100% complete) that creates a DataTable and loads all Contact information into it (skipping any columns that are in a list to ignore). It uses the MutableEntityFieldDescriptor object to get the value for the given contact. This is pretty generic, so with a few changes it could also be applied to other entities like Companies, Opportunities, etc.

 

 Dim actf As Act.Framework.ActFramework
        Try

            actf = New Act.Framework.ActFramework
            actf.LogOn(strLiveDB, userName, password)

            Dim conList As Act.Framework.Contacts.ContactList
            conList = actf.Contacts.GetContacts(Nothing, Nothing, Nothing)  'get all contacts

            dt = New DataTable
            dt.Columns.Add("ID", GetType(String))
            Dim fds() As Act.Framework.MutableEntities.MutableEntityFieldDescriptor = actf.Contacts.GetMutableEntityFieldDescriptors()  'get all field descriptors for Contacts
            For Each fd As Act.Framework.MutableEntities.MutableEntityFieldDescriptor In fds    'loop through all descriptors

                If columnsToIgnore.Contains(fd.DisplayName) = False Then    'check for columns to ignore (just a string list of field names)

                    Dim dc As New DataColumn(fd.DisplayName)

                    Select Case fd.ACTFieldType
                        Case Is = Act.Framework.Database.FieldDataType.Character, Act.Framework.Database.FieldDataType.Memo
                            dc.DataType = GetType(String)
                        Case Is = Act.Framework.Database.FieldDataType.Date, Act.Framework.Database.FieldDataType.DateTime
                            dc.DataType = GetType(DateTime)
                        Case Is = Act.Framework.Database.FieldDataType.YesNo
                            dc.DataType = GetType(Boolean)
                        Case Is = Act.Framework.Database.FieldDataType.Number, Act.Framework.Database.FieldDataType.Currency, Act.Framework.Database.FieldDataType.Decimal, Act.Framework.Database.FieldDataType.TinyInt
                            dc.DataType = GetType(Double)
                    End Select

                    dt.Columns.Add(dc)
                End If
            Next

            For Each con As Act.Framework.Contacts.Contact In conList   'loop through all contacts
                Dim dr As DataRow = dt.NewRow
                dr("ID") = con.ID.ToString
                For Each fd As Act.Framework.MutableEntities.MutableEntityFieldDescriptor In fds    'loop through all field descriptors
                    If columnsToIgnore.Contains(fd.DisplayName) = False Then
                        Dim obj As Object = fd.GetValue(con)    'GET THE VALUE OF THE FIELD FOR THE SPECIFIC CONTACT!

                        If obj Is Nothing Then
                            dr(fd.DisplayName) = DBNull.Value
                        Else
                            dr(fd.DisplayName) = obj
                        End If
                    End If
                Next

                dt.Rows.Add(dr)
            Next

        Catch ex As Exception
            MessageBox.Show(ex.Message & Environment.NewLine & Environment.NewLine & ex.StackTrace, "Error Getting Contact Data", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If actf IsNot Nothing Then
                actf.LogOff()
            End If

        End Try