Community
Showing results for 
Search instead for 
Do you mean 
Reply

New babe to SDK - 1 : C# retrieve Contact field value and update field value by ContactID and field Displayname

Tuned Listener
Posts: 14
Country: Australia

New babe to SDK - 1 : C# retrieve Contact field value and update field value by ContactID and field Displayname

[ Edited ]

Hi there,

 

I am new to SDK and C#. Following the ACT Archetecture, I am able to logon ACT with SDK and test some functional sample codes.

 

Can anyone help me with the below problems? Sample code is preferred.

 

1. retrieve field value by ContactID and FieldDisplayname

2. update the field value by ContactID and FieldDisplayname

 

By the way, I have 5 extended (customizing) Contact tables. (too many tables/fields with long table/field name) So I want to update the field by displayname rather than real table names and field names.

 

 

I have worked out 4 solutions for my problem:

 

static void Main(string[] args)
        {

            ActFramework act = new ActFramework();
            act.LogOn("C:/ACT/test.pad","admin","root");

 

            Console.WriteLine(act.Contacts.ContactPermission); // test permission

            //string ContactID = "F318EFFC-D679-4721-B6E3-6EEE350EE7A9";            

            Contact actContact = act.Contacts.GetMyRecord();//act.Contacts.GetContactsByID(******);

            Console.WriteLine(actContact.ID);   

 

            //key to use MutableEntityFieldSescriptor  

            MutableEntityFieldDescriptor[] myCons = act.Contacts.GetMutableEntityFieldDescriptors();            

            DBFieldDescriptor contactField = null;

 

            //initate for solution 2

            ContactFieldDescriptor ctField = act.Contacts.GetContactFieldDescriptor("CUST_ContactTable2_122431.CUST_Age_122551875");

 

            for (int i = 0; i < myCons.Length; i++)            

           {                

                          contactField = myCons[i];                

                          if (contactField.DisplayName.ToUpper().Equals("AGE"))                

                          {                    

                                      Console.WriteLine(contactField.DisplayName);  

            

//get the existing value from CUST_ContactTable2_122431.CUST_Age_122551875       (table.field)

                                      Console.WriteLine(contactField.GetValue(actContact)); 

//solution 1 to set value                   

                                      contactField.SetValue(actContact, "110");                    

                                      Console.WriteLine(contactField.GetValue(actContact));                    

//solution 2 to set value

                                      ctField.SetValue(actContact, "130");                    

                                      Console.WriteLine(contactField.GetValue(actContact));    

//solution 3 to set value                

                                      actContact.Fields[contactField.Name, true] = "140";

                                      Console.WriteLine(contactField.GetValue(actContact));

//solution 4 to set value //from twolfram

                                      actContact.Fields["Age",FieldNameType.Alias] ="150";

                                      Console.WriteLine(contactField.GetValue(actContact));

 

                                      actContact.Update();               

                          }            

         }

 

Console.ReadLine();

}

1.JPG

 

Copper Contributor
Posts: 42
Country: Germany

Re: New babe to SDK - 1 : C# retrieve Contact field value and update field value by ContactID and field Displayname

actContact.Fields["Department",Act.Framework.MutableEntities.FieldNameType.Alias] ="Value to set";

 

Tuned Listener
Posts: 14
Country: Australia

Re: New babe to SDK - 1 : C# retrieve Contact field value and update field value by ContactID and field Displayname

[ Edited ]

actContact.Fields["Age",Act.Framework.MutableEntities.FieldNameType.Alias] ="150";  //seems not working.

 

actContact.Fields["Age",FieldNameType.Alias] ="150"; //working

 

Thanks, twolfram!