Community
Showing results for 
Search instead for 
Do you mean 
Reply

CreateContact programatically

Accepted Solution Solved
Nickel Elite Contributor
Posts: 508
Country: USA
Accepted Solution

CreateContact programatically

I must be missing something here, but following the SDK example, I cannot get this to work:

 

Dim NewContact As Contact
NewContact = ActFwk.Contacts.CreateContact()
NewContact.Company = "Company Name"
NewContact.FullName = "Contact Name"
NewContact.Fields["TBL_CONTACT.USER1", True] = "Some Data"

It's only the last line that is throwing an error (adding data via the first two lines works - but I need more than just those two)  The error is:

 

Property access must assign to the property or use its value.

 

Thanks for any help...

 

p.s. this is the VB example, and is in MS VS 2008

Richard Brust
ACT! Certified Consultant
richard@rbrDataSolutions.com

Accepted Solutions
Solution
Accepted by topic author rbrust
‎09-25-2015 03:20 AM
Copper Super Contributor
Posts: 59
Country: USA

Re: CreateContact programatically

Hi Richard,

 

Since your code is in vb, you should use ( ) in vb.net instead of [ ] for c#. So try this line instead:

 

NewContact.Fields("TBL_CONTACT.USER1", True) = "Some Data" 

Hugo Vale
Datastream Custom Solutions
http://www.datastreamcs.com

View solution in original post


All Replies
Solution
Accepted by topic author rbrust
‎09-25-2015 03:20 AM
Copper Super Contributor
Posts: 59
Country: USA

Re: CreateContact programatically

Hi Richard,

 

Since your code is in vb, you should use ( ) in vb.net instead of [ ] for c#. So try this line instead:

 

NewContact.Fields("TBL_CONTACT.USER1", True) = "Some Data" 

Hugo Vale
Datastream Custom Solutions
http://www.datastreamcs.com
Nickel Elite Contributor
Posts: 508
Country: USA

Re: CreateContact programatically

Thanks, and you know what bugs me most is *I know that*!!!  I have to change [] to () all the time, but I guess this one just passed me by.  Thanks!
Richard Brust
ACT! Certified Consultant
richard@rbrDataSolutions.com
Copper Contributor
Posts: 51
Country: United States

Re: CreateContact programatically

Does ACT use a primary key field for a Contact?  If so, does anyone have a sample of the code that will both create a new contact as rbrust does in his code sample in this post AND return back the value of the primary key value for the newly created record?

 

If this capability exists is it guaranteed to return the PK for the contact created by the current connection?  That is, in a multiuser or web application where it is possible that multiple contacts could be created in quick succession I need to ensure that if one user's process requests the PK that they aren't getting back the PK of a Contact created by another user's process.  (I'm basically looking for the @@Identity value from the creation for any SQL developers out there.)

 

Environment is VB winforms and ASP.Net on the enterprise version of ACT on SQL Server Developer's edition back end. 

 

VB would be best but I can figure our C# if that's what you have. 

 

Thanks,

 

Larry

Copper Super Contributor
Posts: 59
Country: USA

Re: CreateContact programatically

Hi Larry,

 

You can use RBrust code and then in the end you can just check the ID property. It will return the PK that you looking for. Don't worry, this will be PK belonging to this contact and not from another user how sometimes it could happen using @@IDENTITY on SQL.

 

Here's the code:

Dim NewContact As Contact
NewContact = ActFwk.Contacts.CreateContact()
NewContact.Company = "Company Name"
NewContact.FullName = "Contact Name"

NewContact.Fields["TBL_CONTACT.USER1", True] = "Some Data

NewContact.Update()

messagebox.show(NewContact.ID.ToString)        <----- this will display the PK you are looking for (It's a GUID)

Hugo Vale
Datastream Custom Solutions
http://www.datastreamcs.com
Copper Contributor
Posts: 51
Country: United States

Re: CreateContact programatically

Many thanks, Hugo.  This is very valuable.