Community
Showing results for 
Search instead for 
Do you mean 
Reply

Newbie - 1) trying to get the current contact ; 2) learning to use SDK

Tuned Listener
Posts: 8
Country: United States

Newbie - 1) trying to get the current contact ; 2) learning to use SDK

I have some experience with .NET programming, but am fairly new at it and need help in getting started with the ACT!2008 SDK.

 

I am running version 10.0.3.

 

1. I'd like to get the field values for the current record in ACT! - the record that is visible in the Contact Detail view.  How do I program (in VB) to get the current record, and the field values? Also, how do I write field values to the current record?

 

2. Where would you recommend I start to learn the SDK. I have the SDK reference available on my computer, but I'm looking for other resources - online or in books.

 

Any recommendations?

 

Thanks!

 

Kim Kamper 

Tuned Listener
Posts: 11
Country: United States

Re: Newbie - 1) trying to get the current contact ; 2) learning to use SDK

Hi Kim,

 

I'm in a similiar situation. I've been programming engineering apps in various languages (AutoLISP, VBA, VB 6, C#, & VB.net) for over 10 years but I'm having a tough time getting started with the ACT SDK.

 

I'm learning this too so forgive me or ignore me if someone has a better idea ;-)  Once you have the SDK downloaded, take a look at the Act20081002.chm found in the \code reference folder. There is namespace named Contacts that might be helpful. The namesapce has a ContactManager class. Poke around in there and see if that helps.

 

I plan to dig into the ContactManager::CreateContact() method but haven't been able to figure out how to connect to Act via the plugin and make a menubar to run my command from. The API (create a contact, modify fields, etc) seems straightforward for me but getting it hooked up into a plugin seems confusing or at least poorly documented.

 

I hope I was able to point you in the right direct at least. Good Luck,

Scott

 

Nickel Super Contributor
Posts: 441
Country: UK

Re: Newbie - 1) trying to get the current contact ; 2) learning to use SDK

Hi Kim,

Below are a couple of samples, you can paste them into the act sdk demo plugin and call them from there, hope it helps...

 

Private Sub WriteToCurrentContact() 'create a contact object Dim contact As Act.Framework.Contacts.Contact 'get the current contact contact = ActApp.ApplicationState.CurrentContact 'set the address 1 field (the false parameter indicates we are using a display 'name not a true field name) contact.Fields("Contact.Address 1", False) = "Address 1 Here" 'save the contact contact.Update() End Sub Private Sub GetCurrentContactField() 'create a contact object Dim contact As Act.Framework.Contacts.Contact 'get the current contact contact = ActApp.ApplicationState.CurrentContact 'get the address 1 field value Dim Add1 As String = contact.Fields("Contact.Address 1", False) 'display the value MsgBox(Add1) End Sub

 

Tom
Tuned Listener
Posts: 8
Country: United States

Re: Newbie - 1) trying to get the current contact ; 2) learning to use SDK

Thanks for the code.

 

When I run it, I get the following error.

 

"Exception System.NullReferenceException was thrown in debuggee:
Object reference not set to an instance of an object. "

 

Am I missing some declarations earlier?

 

If possible, could you show or email a full module showing the programming flow BEFORE these Private Subs?

 

Thanks!

 

Kim 

Bronze Elite Contributor
Posts: 2,115
Country: United_Kingdom

Re: Newbie - 1) trying to get the current contact ; 2) learning to use SDK

Hi Kim,

 

My Tupence worth would be to suggest first try getting a feel for the ACT! SDK via the framework first before going into creating Plugins. There is very little direct documentation on creating plugins and Toolbar Buttons and Menu Bar items etc and to be honest I find it a bit "arcane" still myself!

The ACT! SDK has some real idiocyncracies and its best to get to grips with the general weirdness of ACT! first then go onto Plugins...well that is what I found worked for me anyway!

 

2. If you are in the UK I know that they run a really good course up in Newcastle by Chris Burke who was the guy who made sense of the SDK to me from version 7.

 

The thing that I found most handy when I was learning was to remember to use the Entity Managers for most tasks which come from the ActFramework object. e.g we want to get at all the contacts in the dB your access level allows: (my apologies its in C#)

 

//--------- instantiating the ActFramework object and Logining in----------------

Act.Framework.ActFramework oFram = new Act.Framework.ActFramework();

oFram.Logon(strPath,StrUser,strPass);

//-----------------------------------------------------------------------------

MessageBox.Show(oFram.Contacts.GetContacts(null).Count.ToString());

 

Basically the last line uses the ActFramework ContactManager's (oFram.Contacts) method GetContacts(null) to return a ContactList collection object. The parameter null just declares that there is no SortCriteria for the returned ContactList. For small dBs I have stopped bothering with the extra code for setting sort criteria dn use .NET 3.5's Lamda Expressions to do this by iterating the Act Collection into a generic list.

 

Hope I haven't been teaching grannies to suck eggs here and its been of use to someone!

 

Vivek

 

Vivek Gargav
Caldere Associates Ltd.
www.caldere.com
vgargav@caldere.com
My Blog
Copper Contributor
Posts: 70
Country: USA

Re: Newbie - 1) trying to get the current contact ; 2) learning to use SDK

And of course, the Try/Catch Error Trap may help too.


Dim cContact As Contact = ActApp.ApplicationState.CurrentContact
Dim cField As ContactFieldDescriptor = ActApp.ActFramework.Contacts.GetContactFieldDescriptor("TBL_CONTACT.FULLNAME")
Dim oValue As Object = cField.GetValue(cContact)
Dim cField2 As ContactFieldDescriptor = ActApp.ActFramework.Contacts.GetContactFieldDescriptor("TBL_CONTACT.COMPANYNAME")
Dim oValue2 As Object = cField2.GetValue(cContact)
'============ 
'GET THE GUID - No need for an error trap - everybody's got one of these :-)
'============ 
  Dim ID As String = cContact.ID.ToString
'======================
'GET THE CONTACT'S NAME
'======================
 Try
   ContactName = oValue.ToString()
 Catch
   ContactName = ""
 End Try 
'=========================
'GET THE CONTACT'S COMPANY
'=========================
 Try
   CompanyName = oValue2.ToString()
 Catch
   CompanyName = ""
 End Try
 
Cheers,
Kevin
==========
Kevin Ritch
V8Software.com
New York

Tuned Listener
Posts: 8
Country: United States

Re: Newbie - 1) trying to get the current contact ; 2) learning to use SDK

Thanks for the code!

 

I put your code in, and tried to run as an exe file.

 

I get the error message:

 

     "Exception System.NullReferenceException was thrown in debuggee:
     Object reference not set to an instance of an object. "

 

The following is the complete code from the Module that I am running this in.

 

I would REALLY appreciate any insight as to why this is throwing an error.

 

'****************************************************** 

Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Windows.Forms
Imports System.ComponentModel

Imports Act.Framework
Imports Act.UI
Imports Act.Framework.Contacts
Imports Act.Framework.ComponentModel.Core

'REFERENCES in this Project:
' Act.Framework
' Act.Framework.ComponentModel.Core
' Act.Shared.Collections
' Act.Shared.Diagnostics
' Act.UI
' Act.UI.Contacts.Views
' Act.UI.Core
' System
' System.data
' System.Drawing
' System.Windows.Forms
' System.Xml

Public Module Module1
    
     Dim ActApp As ActApplication
    
     Sub Test()
         '============
         'LOGIN to ACT!
         '============
         Dim strPath As String = "C:\Program Files\ACT\Act for Windows\Database\GLFM.pad"
         Dim strUser As String = "Kim"
         Dim strPass As String = "k2"
         Dim fFram As New Act.Framework.ActFramework()
         fFram.Logon(strPath, strUser, strPass)
         '============
         'Set up variables
         '============        
         Dim ContactName As String
         Dim CompanyName as String
         Dim cContact As Act.Framework.Contacts.Contact = ActApp.ApplicationState.CurrentContact
         Dim cField As ContactFieldDescriptor = ActApp.ActFramework.Contacts.GetContactFieldDescriptor("TBL_CONTACT.FULLNAME")
         Dim oValue As Object = cField.GetValue(cContact)
         Dim cField2 As ContactFieldDescriptor = ActApp.ActFramework.Contacts.GetContactFieldDescriptor("TBL_CONTACT.COMPANYNAME")
         Dim oValue2 As Object = cField2.GetValue(cContact)
         '============
         'GET THE GUID - No need for an error trap - everybody's got one of these :-)
         '============
         Dim ID As String = cContact.ID.ToString
         '======================
         'GET THE CONTACT'S NAME
         '======================
         Try
             ContactName = oValue.ToString()
         Catch
             ContactName = ""
         End Try
         '=========================
         'GET THE CONTACT'S COMPANY
         '=========================
         Try
             CompanyName = oValue2.ToString()
         Catch
             CompanyName = ""
         End Try
        
     End Sub
    
     End Module

'******************************************************

 

Thanks for your help!

 

Kim 

Bronze Elite Contributor
Posts: 2,115
Country: United_Kingdom

Re: Newbie - 1) trying to get the current contact ; 2) learning to use SDK

Hi Kimkamp,

 

Ok when you create an exe file you will be using the framework model i.e an external program that will have its own UI and access the dB via a logon(). To write something that caninteract with the Act! UI as the logged on user you will need to create a Plugin. When compiled this will create a dll. If memory serves me right there should be  link here somewhere that allows you to download a VS Project Template for creating ACT! Plugins.

 

In the manner you are trying to use the code the ActApplication object will always be null since the independent exe is unaware of what ACT! or the ActApplication object is (sorry I know I'm not making much sense here!). Here is some code basically copied from the ActDevNet plugin template. Sorry its in C# but you can convert it to VB.net via some online free converters:

using System;

using System.Collections.Generic;

using System.Text;

using System.Windows.Forms; // needed for ACT! application

using System.Diagnostics;

using System.Reflection;

using Act.Shared.Diagnostics; // needed for logging

using Act.Framework; // needed for any framework access

using Act.UI; // needed as a Plugin to handle the ActApplication

namespace Act.DevNet.Extensibility.Plugin1

{

public class Plugin : IPlugin

{

private ActApplication application; // application context

private Act.Shared.Diagnostics.TraceSwitch traceSwitch; // logging

 void IPlugin.OnLoad(ActApplication application)

{

// hold on to the application

 this.application = application;

// be sure to keep track of when a user logs in or is logged out

application.AfterLogon += new EventHandler(Application_AfterLogon);

application.BeforeLogoff += new EventHandler(Application_BeforeLogoff);

try

{

// do any critical initialization here

}

catch (Exception ex)

{

if (traceSwitch.TraceError)

{

Act.Shared.Diagnostics.
Trace.WriteLine(ex, traceSwitch.Category, TraceLevel.Error);

}

}

 

// log that we've loaded

traceSwitch = new Act.Shared.Diagnostics.TraceSwitch(Assembly.GetExecutingAssembly());

if (traceSwitch.TraceInfo)Act.Shared.Diagnostics.

Trace.WriteLine(string.Format("Plugin {0} successfully initialized.", Assembly.GetExecutingAssembly().FullName),traceSwitch.Category, TraceLevel.Info);

 

}

void IPlugin.OnUnLoad()

{

// this is equivalent to being disposed,

// so make sure to detach from any events

 if (application != null)

{

application.AfterLogon -=
new EventHandler(Application_AfterLogon);

application.BeforeLogoff -= new EventHandler(Application_BeforeLogoff);

ActFramework framework = application.ActFramework; if (framework != null)

{

framework.Database.BeforeDatabaseLock -=
new Act.Framework.Database.DatabaseLockHandler(Database_BeforeDatabaseLock);

}

}

try

{

// do any critical tear-down here

}

catch (Exception ex)

{

if (traceSwitch.TraceError)

{

Act.Shared.Diagnostics.
Trace.WriteLine(ex, traceSwitch.Category, TraceLevel.Error);

}

}

}

 

private void Application_AfterLogon(object sender, EventArgs e)

{

// keep track of when we're about to be locked out

application.ActFramework.Database.BeforeDatabaseLock += new Act.Framework.Database.DatabaseLockHandler(Database_BeforeDatabaseLock);

try

{

//TODO: do any critical work here

}

catch (Exception ex)

{

if (traceSwitch.TraceError)

{

Act.Shared.Diagnostics.
Trace.WriteLine(ex, traceSwitch.Category, TraceLevel.Error);

}

}

 

}

private void Application_BeforeLogoff(object sender, EventArgs e)

{

// make sure to detatch from anything framework/database/user related events,

//as we are about to be logged out

try

{

//TODO: do any work here

}

catch (Exception ex)

{

if (traceSwitch.TraceError)

{

Act.Shared.Diagnostics.
Trace.WriteLine(ex, traceSwitch.Category, TraceLevel.Error);

}

}

}

 

private void Database_BeforeDatabaseLock(object sender, Act.Framework.Database.DatabaseLockInformation databaseLockInformation)

{

//TODO: we're about to be forced out, so perform any cleanup

try

{

//TODO: do any work here

}

catch (Exception ex)

{

if (traceSwitch.TraceError)

{

Act.Shared.Diagnostics.
Trace.WriteLine(ex, traceSwitch.Category, TraceLevel.Error);

}

}

}

 

}

}

 

Once you have copied and pasted it into a new dll project let me and I will try and walk you through it and then we can put in some of the code you would like to.

 

HTH

Vivek

Vivek Gargav
Caldere Associates Ltd.
www.caldere.com
vgargav@caldere.com
My Blog
Copper Contributor
Posts: 70
Country: USA

Re: Newbie - 1) trying to get the current contact ; 2) learning to use SDK

Hi there.

 

ActApp is really to be used in a Class in a DLL plugin.

 

An exe would use the Framework.

 

Why not try using one of the examples that come with the SDk and then put the code Tom or I posted.

 

(With the error trapping).

 

Best,
Kevin

Copper Contributor
Posts: 70
Country: USA

Re: Newbie - 1) trying to get the current contact ; 2) learning to use SDK

[ Edited ]

Hi Kim,

 

If you go to this link, you can download ALL of the examples and VB.Net sample projects.

 

http://www.act.com/partners/addonpartners/sdk/index.cfm

 

The form they make you fill in takes about 2 minutes - then download EVERY zip file they offer you. Sadly if you just download one of them and then want to come back again later, you are forced to fill in the dratted form each time.

 

ACT! 2009 (11.0) SDK
ACT! 2008 (10.0) SDK
ACT! 2007 (9.0.X) SDK
ACT! Premium for Web 2007 (9.0.X) SDK
ACT! 2006 (8.0.X) SDK
ACT! 2005 (7.0.X) SDK

 

After downloading, don't be too shy to try the OLDER examples for earlier versions - play and learn. Google around where any issues arise with the actual error messages. It does help.

 

There are essentially 3 types of ways of working with ACT!

 

ODBC - Read Only using the ACTOLEDB object. Search around and Google for examples. There are folk out there who use this to move customers from ACT! to MS CRM - so they have posted some good stuff out there that I found useful.

 

And also bear in mind that ACTDiag is the easiest way to report on data structures to get Field Names.

 

Another tip is to use sites such as:

 

http://labs.developerfusion.co.uk/convert/csharp-to-vb.aspx

 

...to convert C# stuff to VB.Net here and there. It's not the be-all-and-end-all way - but it's useful.

 

Also, download and use the FREE version of VB.net 2008 Express from Microsoft.

 

Warning - don't use the FREE version for AddOn Development, but rather, to convert simple VB6 code samples to their .Net equivalent without mucking up any SDK stuff.

 

ACTAPP - for PlugIns that are executed by and within ACT that are compiled as DLLs and stuck (together with their counterpart .PDB files) into C:\Program Files\ACT\Act for Windows\Plugins

 

...and of cource, EXE's with the ACTFWK stuff that can be executed directly.

 

Don't forget to put all the various resources into a single simple-to-find folder so that you can grab them easily.

 

You do not, however, wish to mix different versions of the components if that can be avoided.

 

I use C:\ACT2008SDK_V10_2_Resources\ for mine - it just makes it easy for me - but you should do what works best for you.

 

Unlike VB6 programming (et al) you do not have to use RegSvr32 to "register" your DLLs like you have to with traditional programming methods.

 

ACT by Sage (as opposed to Symantec ACT!) just "knows" how to deal with the DLL/PDB combination of files inasmuch as they are interpreted by ACT through the .Net thingy, and not by Windows.

 

If I have in ANY way sounded at all parental or condescending, please know that this was never my intention. I realize that you are probably already a groovy programmer with experience - and whilst perhaps it may have seemed that I was teaching your granny to suck eggs, I have actually just outlined everything I did myself over the past 2 and a half, to 3 months - switching (screaming, moaning and swearing along the way) from VB6 (the REAL die-hard VB programmer that I am) to VB.net.

 

So I too am somewhat of a newbie with vb.net albeit I have been programming non-stop for a living since 1983 for my sins.

 

:-) 

 

Enjoy - and good luck. It's all quite fun when you get the hang of it.

 

Neat dudes out there such as Stan Smith and Tom Davis and that cool Kangaroo Rider, Mike Lazarus are always out there to grab you by the shoulders from time-to-time to steer you in the right direction.

 

And the rest of the community too - of course.

 

Cheers,
Kevin

 

PS - Sorry, I am using logMeIn from home today - and I type too fast. So occasionally, letter get missed and I keep editing the posting. (Well that's my excuse and i am sticking to it)

Message Edited by kritguy on 08-28-2008 11:28 AM