Community
Showing results for 
Search instead for 
Do you mean 
Reply

Custom table c#, accesing its fields and setting values c#

New Member
Posts: 9
Country: USA

Custom table c#, accesing its fields and setting values c#

[ Edited ]

I have created a custom table under contacts with an act plugin. I am really close to getting the field but something i must be missing. My code is this:

 

CustomEntityDescriptor multilingualsDescriptor = ACTFM.CustomEntities.GetCustomEntityDescriptor("multilinguals");

CustomSubEntityManager<MLTable> manager2 = ACTFM.CustomEntities.GetSubEntityManager<MLTable>("multilingualsDescriptor ");

Act.Framework.CustomEntities.CustomEntityFieldDescriptor descr = manager2.GetCustomEntityFieldDescriptor("Spanish", FieldNameType.Alias);
CustomEntityList<MLTable>listofML;

 

I have also added a class 

public MLTable(CustomSubEntityInitializationState state)
: base(state)
{

}

How can i set to a MulitlingualTable(Custom table, subentity of Contact ) the Spanish field as true??  Is there an equivelant for the code below that i used to get  a custom field named "test" from Contacts(not a custom Table) :


ContactFieldDescriptor asdfff = ACTFM.Contacts.GetContactFieldDescriptor("test", FieldNameType.Alias);
ContactList cfdList;
SortCriteria[] sCriteria = { new SortCriteria(asdfff, ListSortDirection.Descending) };

cfdList = ACTFM.Contacts.GetContacts(sCriteria);
int NumContacts = cfdList.Count;
string allnames = "";
for (int i = 0; i < cfdList.Count; i++)
{

Contact cfd = cfdList[i];
allnames = allnames + "" + cfd.FullName;

 

}

ContactFieldDescriptor asdfff = ACTFM.Contacts.GetContactFieldDescriptor("test", FieldNameType.Alias);

ContactList cfdList;


SortCriteria[] sCriteria = { new SortCriteria(asdfff, ListSortDirection.Descending) };

 

cfdList = ACTFM.Contacts.GetContacts(sCriteria);
int NumContacts = cfdList.Count;


string allnames = "";

for (int i = 0; i < cfdList.Count; i++)
{

Contact cfd = cfdList[i];
allnames = allnames + "" + cfd.FullName;

}

 

By the way i have found some usefull information in this post: http://community.act.com/t5/Act-Developer-s-Forum/Change-a-Custom-Sub-Entity-field-DisplayName/m-p/2... and in this pdf that was attached in another post: http://community.act.com/sage/attachments/sage/ADN_Downloads/4/1/Custom%20Sub-Entities%20SDK%20Guide...

 

Thanks 

Bronze Super Contributor
Posts: 1,231
Country: USA

Re: Custom table c#, accesing its fields and setting values c#

[ Edited ]

We created a fcuntion to add a contact to en exisiting custom entity by passing the actFramework, the custom entity and the contact to be attached. This works if its the first contact or the 100th.

 

  Public Shared Function AddContactToEntity(ByVal HostFramework As Act.Framework.ActFramework, _
                                              ByVal cCustomSubEntityDurkin As CustomSubEntityDurkin, _
                                              ByVal cContact As Act.Framework.Contacts.Contact) As Boolean

        Try
            '-----------------------------------------
            ' Create an array to hold Contact IDs
            '-----------------------------------------
            Dim aContactIDs As ArrayList = New ArrayList

            '-------------------------------------------
            ' Add the cContactID which was passed to us 
            '-------------------------------------------
            aContactIDs.Add(cContact.ID)

            '-------------------------------------------
            ' Add all the contacts which are currently attached
            ' to the current cCustomSubEntityDurkin
            '-------------------------------------------
            Dim ContactList As Act.Framework.Contacts.ContactList = cCustomSubEntityDurkin.GetContacts(Nothing)
            If Not ContactList Is Nothing Then
                For Each CurrentContact As Act.Framework.Contacts.Contact In ContactList
                    aContactIDs.Add(CurrentContact.ID)
                Next
            End If

            '---------------------------------------------
            ' Convert the array into the guids array
            '---------------------------------------------
            Dim ContactIDs(aContactIDs.Count - 1) As System.Guid
            Dim xCounter As Integer = 0
            Dim item As Object
            For Each item In aContactIDs
                ContactIDs(xCounter) = CType(item, System.Guid)
                xCounter = xCounter + 1
            Next

            '---------------------------------------------
            ' Use the SetContacts function to set all the 
            ' desired contacts to the current CustomSubEntity
            '---------------------------------------------
            cCustomSubEntityDurkin.SetContacts(HostFramework.Contacts.GetContactsByID(Nothing, ContactIDs))

            Return True

        Catch ex As Exception
            Throw ex
            Return False
        End Try

    End Function

 

Here is the reverse function to remove a single contact.

 

 Public Shared Function RemoveContactFromEntity(ByVal HostFramework As Act.Framework.ActFramework, _
                                                  ByVal cCustomSubEntityDurkin As CustomSubEntityDurkin, _
                                                  ByVal cContact As Act.Framework.Contacts.Contact) As Boolean

        Try
            '-----------------------------------------
            ' Create an ArrayList fot the ContactIDS 
            '-----------------------------------------
            Dim aContactIDs As ArrayList = New ArrayList

            '-------------------------------------------
            ' Get all the contacts from CurrentEntity 
            ' Except the contact we want to remove
            '-------------------------------------------
            Dim ContactList As Act.Framework.Contacts.ContactList = cCustomSubEntityDurkin.GetContacts(Nothing)
            If Not ContactList Is Nothing Then
                For Each CurrentContact As Act.Framework.Contacts.Contact In ContactList
                    If CurrentContact.ID <> cContact.ID Then
                        aContactIDs.Add(CurrentContact.ID)
                    End If
                Next
            End If

            '---------------------------------------------
            ' Create a List Of GUIDS based on the aContactIDs
            ' Move the aContactIDs into the guids array
            '---------------------------------------------
            Dim ContactIDs(aContactIDs.Count - 1) As System.Guid
            Dim xCounter As Integer = 0
            Dim item As Object
            For Each item In aContactIDs
                ContactIDs(xCounter) = CType(item, System.Guid)
                xCounter = xCounter + 1
            Next

            '---------------------------------------------
            ' Set the New Contact List 
            '---------------------------------------------
            cCustomSubEntityDurkin.SetContacts(HostFramework.Contacts.GetContactsByID(Nothing, ContactIDs))

            Return True

        Catch ex As Exception
            Throw ex
            Return False
        End Try

    End Function

 

 

Hope this helps

-- Jim Durkin