09-12-2016 03:40 PM
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
09-13-2016 04:27 AM - edited 09-13-2016 04:28 AM
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.
09-13-2016 06:17 AM
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