Community
Showing results for 
Search instead for 
Do you mean 
Reply

Newbie trying to update a Contact field

New Member
Posts: 5
Country: USA

Newbie trying to update a Contact field

I have searched the Forum and the SDK documentation and I am having a hard time finding what I need. I have an application I am writing and all I am trying to do is edit some custom YES/NO fields. I would prefer to do this by CONTACTID which i am obtaining via the ACT Reader tool. HELP!

Employee
Posts: 1,163
Country: USA

Re: Newbie trying to update a Contact field

[ Edited ]

Hello LesPaul,

 

You can retrieve a contact via ID like this:

 

Contact c = afw.Contacts.GetContactsByID(myID);

 

Once you've captured the contact you can update their fields either by capturing the FieldDescriptor for your field and then calling the SetValue method for the field.

 

ContactFieldDescriptor YesNoContactField = ActApp.ActFramework.Contacts.GetContactFieldDescriptor("TBL_CONTACT.CUST_YesandNo_020852428");

Contact contact = ActApp.ApplicationState.CurrentContact;
YesNoContactField.SetValue(contact, true);

 

Or by using the contact's field property and assigning a value

 

c.Fields["YourFieldName", true] = true;

Matthew Wood
Act! SDK Support
Community Moderator
New Member
Posts: 5
Country: USA

Re: Newbie trying to update a Contact field

Forgive my complete obliviousness to the SDK. to clarify more. I am doing this in VB. do i need to define something prior for that to work? 

Employee
Posts: 1,163
Country: USA

Re: Newbie trying to update a Contact field

[ Edited ]

You'd need to add a reference to Act.Framework.dll, Act.Shared.Collections and then imports statements for Act.Framework and Act.Framework.Contacts. If this is a framework application you'll also need to create an instance of the ActFramework object and call it's LogOn method.

 

Once your logged onto the framework you'll have the access you need to do what you've described.

 

I think I also may have left off some of the parameters from the GetContactsByID method, should be GetContactsByID(sortCriter(), contactKeys(), ContactList).

 

The one's where you see ActApp.ActFramework look that way because it was done in a plug-in rather than a framework applicationi, you'd just replace ActApp.ActFramework with your instantiated ActFramework object.

Matthew Wood
Act! SDK Support
Community Moderator
Employee
Posts: 1,163
Country: USA

Re: Newbie trying to update a Contact field

Also here's what I wrote earlier in VB in case you aren't able to translate

Dim contact As Contact = _afw.Contacts.GetMyRecord()
Dim contactKeys(1) As Guid
contactKeys(0) = _afw.Contacts.GetMyRecord().ID
Dim myRecordByID = _afw.Contacts.GetContactsByID(Nothing, contactKeys)


Dim contactFields As ContactFieldDescriptor = _afw.Contacts.GetFieldDescriptor("YourYesNoFieldName")
contactFields.SetValue(contact, True)

contact.Fields("YourYesNoFieldName") = True
Matthew Wood
Act! SDK Support
Community Moderator
New Member
Posts: 5
Country: USA

Re: Newbie trying to update a Contact field

I have everything I need imported. And I can access what you are talking about but I get errors and I do not believe I am writing the statement correctly. Lets say I have an ID: 

 

063551df-33b0-4141-b415-6628dd49e3a2

 

I just want info for that single Contact ID.

 

I have this, what am I missing?

 

Dim ActFwk as new Act.framework.Actframework

Actfwk.Logon(user, Pass, Host, DB)

 

actfwk.contact.getcontactsbyid(063551df-33b0-4141-b415-6628dd49e3a2)

 

Obviously that is not correct.

Employee
Posts: 1,163
Country: USA

Re: Newbie trying to update a Contact field

It's throwing build errors likely because there is no method that accepts parameters of that type.

 

The best match would be GetContactByID(sortCriter() As Act.Shared.Collection.SortCriteria, contactKeys() As System.Guid) in other words you need a collection of sort criteria (or Nothing) and a collection of Guid's. You can create a collection of Guid's like:

 

Dim guid As Guid = New Guid("063551df-33b0-4141-b415-6628dd49e3a2")
Dim contactKeys(1) As Guid
contactKeys(0) = guid

 

At this point you have both of the parameters required to get your contact by ID:

 

Dim ContactbyID = _afw.Contacts.GetContactsByID(Nothing, contactKeys)

 

As you type, if your in Visual Studio, intelliesense ought to be letting you know what parameters are required/acceptable as well as any potential overloads.

Matthew Wood
Act! SDK Support
Community Moderator
New Member
Posts: 5
Country: USA

Re: Newbie trying to update a Contact field

Thanks For all your help!! I am starting to understand how this works now. I just have one problem now. here is my code.

 

 

 Dim guid As Guid = New Guid("063551df-33b0-4141-b415-6628dd49e3a2")
        Dim contactKeys(1) As Guid
        contactKeys(0) = guid
        Dim myRecordByID = ActFwk.Contacts.GetContactsByID(Nothing, contactKeys)
        Dim contactFields As ContactFieldDescriptor = ActFwk.Contacts.GetFieldDescriptor("CUST_ContactsTable1_111514.CUST_cert2010UHCAARPmapd_083502624")
        contactFields.SetValue(myRecordByID(0), True)
        myRecordByID.Item(0).Fields("CUST_ContactsTable1_111514.CUST_cert2010UHCAARPmapd_083502624") = True

 

 

It works fine until i get to the last line and it says Invalid Table Name. But i checked that is the table the data i want to change is in.

Employee
Posts: 1,163
Country: USA

Re: Newbie trying to update a Contact field

Is this data coming from a custom table? Otherwise the table name looks incorrect.

The easier way is probably to just use the TableName property for your field descriptor to get the correct string.

Dim tableName = contactFields.TableName.ToString()
Matthew Wood
Act! SDK Support
Community Moderator
New Member
Posts: 5
Country: USA

Re: Newbie trying to update a Contact field

THANKS AGAIN FOR THE HELP!!! I have it working here is the code for anyone else trying to do the same thing.

 

 

 Dim guid As Guid = New Guid("063551df-33b0-4141-b415-6628dd49e3a2")
        Dim contactKeys(1) As Guid
        contactKeys(0) = guid
        Dim myRecordByID = ActFwk.Contacts.GetContactsByID(Nothing, contactKeys)
        Dim contactFields As ContactFieldDescriptor = ActFwk.Contacts.GetFieldDescriptor("CUST_ContactsTable1_111514.CUST_cert2010UHCAARPmapd_083502624")
        contactFields.SetValue(myRecordByID(0), True)
        myRecordByID.Item(0).Update()
        ActFwk.LogOff()