Community
Showing results for 
Search instead for 
Do you mean 
Reply

Retrieve and update contact with ContactID

Copper Contributor
Posts: 28
Country: United_Kingdom

Retrieve and update contact with ContactID

I am trying to get the following code to update a contact with id  {E94D6964-9BDE-4FC5-B625-00D007A67DD4}

 

Public Class Class1

    Public Function CreateContact1() As Boolean
        Dim ActFwk As New Act.Framework.ActFramework
        Const ACTPadFile As String = "C:\Users\Public\Documents\ACT\ACT Data\Databases\ACT2013Demo.PAD"


        ActFwk.LogOn(ACTPadFile, "chris huffman", "")

        Dim actCont As Act.Framework.Contacts.Contact
        actCont = ActFwk.Contacts.GetContactsByID("{E94D6964-9BDE-4FC5-B625-00D007A67DD4}")

        With actCont
            .Company = "MRZ 2"
            .FullName = "Janet Evans"
            .Update()

        End With
        Return True

    End Function

 

 

 

This won't compile   Overload resolution failed because because no accessible 'GetContactsByID' accepts this number of arguments

 

What am I doing wrong ?  Thanks  

Copper Elite Contributor
Posts: 81
Country: Canada

Re: Retrieve and update contact with ContactID

[ Edited ]

For me, the GetContactsByID function needs 2 arguments; a sortcriteria array and a guid array. Try and change the following line in your code.

 

actCont = _actApp.ActFramework.Contacts.GetContactsByID(Nothing, New Guid() {New Guid("E94D6964-9BDE-4FC5-B625-00D007A67DD4")})

Also, GetContactsByID returns a ContactList, not a Contact, so you will need to modify your code accordingly. 

 

Ahsan

 

 

Ahsan Khalid

Chief Technology Officer
Keystroke Quality Computing Inc.
www.keystroke.ca

Copper Contributor
Posts: 28
Country: United_Kingdom

Re: Retrieve and update contact with ContactID

Thank you. Sorry - I now see that I looked at the SDK documentation rather carelessly for the GetContactsByID method !

 

Can you point me at any sample code which handles the ContactList returned by this method ?  If I pass a single ID then presumably only 1 record will be returned. I need to parse the returned object to get individual fields so I can make changes to the data.  Feel free to point me at documentation if I've missed something again !

 

Thanks

 

 

Copper Elite Contributor
Posts: 81
Country: Canada

Re: Retrieve and update contact with ContactID

[ Edited ]

Yeah, it should only return one Contact. Try Something like this

 

Public Function CreateContact1() As Boolean
	Dim ActFwk As New Act.Framework.ActFramework()
	Const  ACTPadFile As String = "C:\Users\Public\Documents\ACT\ACT Data\Databases\ACT2013Demo.PAD"


	ActFwk.LogOn(ACTPadFile, "chris huffman", "")

	Dim lstContact As Act.Framework.Contacts.ContactList = Nothing
	Dim actCont As Act.Framework.Contacts.Contact = Nothing
        actCont = _actApp.ActFramework.Contacts.GetContactsByID(Nothing, New Guid() {New Guid("E94D6964-9BDE-4FC5-B625-00D007A67DD4")})

	If lstContact.Count = 0 Then
		'Contact not found, return or handle error here
	End If

actCont = lstContact(0) With actCont .Company = "MRZ 2" .FullName = "Janet Evans" .Update() End With Return True End Function

 

I am using a C# to Vb converter so pardon any syntax errors.

Ahsan Khalid

Chief Technology Officer
Keystroke Quality Computing Inc.
www.keystroke.ca

Copper Elite Contributor
Posts: 95
Country: USA

Re: Retrieve and update contact with ContactID

Act.Framework.Contacts.Contact AContact = ActFwk.Contacts.GetContactsByID(null, Guid)[0];

 

That of course assumes you get a contact returned from your id, wrap it in some error checking.

 

The way I look for FieldDescriptors is by walking the list for the field type I want, there are other ways to do it, this works for me.

 

public Act.Framwork.Contact.ContactFieldDescriptor FindTheField(string fieldname){

Act.Framework.Contacts.ContactFieldDescriptor[] CFDList = ActFwk.Contacts.GetContactFieldDescriptors();
            for (int i = 0; i < CFDList.Length; i++)
            {
                if (CFDList[i].DisplayName == fieldname) // You can also use .Alias
                    return CFDList[i];
            }

return null; // oh noes, no field

}

 

You just modify the above code for company/opp fields.

 

Also note, you should be calling Contact.Update() before and after pushing changes to fields.

 

Nick Bohne
Effective Solutions, Inc.
Copper Contributor
Posts: 28
Country: United_Kingdom

Re: Retrieve and update contact with ContactID

Thank you both this is exactly what I wanted and helps me take a further step into the SDK mysteries !