Community
Showing results for 
Search instead for 
Do you mean 
Reply

Deleting a contact field

Copper Contributor
Posts: 21
Country: United Kingdom

Deleting a contact field

Hi all,

 

I've created a new contact field as below. If I wanted to delete the field later how would I go about it?

 

            Instance.ActFramework.Database.LockDatabase(Act.Framework.DatabaseLockReason.SchemaChanges)
            Field = New Act.Framework.Database.FieldDescriptor(FieldName, Act.Framework.RecordType.Contact, Act.Framework.Database.FieldDataType.Character)
            Field.Attributes(FieldProperty.Length) = New Act.Framework.Database.LengthAttribute(100)
            Instance.ActFramework.Fields.Save(Field)
            Instance.ActFramework.Database.UnlockDatabase()
            Instance.ActFramework.Fields.RefreshSchema()

Thanks

Luke

 

Copper Contributor
Posts: 21
Country: United Kingdom

Re: Deleting a contact field

I found the solution. There doesn't appear to be any way of getting the specific field without looping through the collection.

        Dim Fields As FieldDescriptorCollection
        Dim FieldName As String = "MyField"

        Fields = ACT.Fields.GetFields(Global.Act.Framework.RecordType.Contact)
        For i As Int32 = 0 To (Fields.Count - 1) Step 1
            If (Fields(i).Alias = FieldName) Then
                ACT.Database.LockDatabase(DatabaseLockReason.SchemaChanges)
                ACT.Fields.Delete(Fields(i))
                ACT.Database.UnlockDatabase()
                ACT.Fields.RefreshSchema()
            End If
        Next