Thursday, May 8, 2008

[Working with Java Beans] Access Quickbooks from Servoy

If you have any clients that need an external application to talk to Quickbooks, ibiz Quickbooks Integrator from /n Software (www.nsoftware.com) may be your answer. They provide a javabean that you can drop into Servoy and quickly begin talking to Quickbooks. This article documents the basic process of connecting to the bean.

Basic installation

  1. Download the Quickbooks Integrator from http://www.nsoftware.com/

  2. Install or unzip the files

  3. Find the file "ibizqb.jar" and copy it to the /servoy/beans" directory

  4. If you want to access the classes and methods of the bean directly without having to place the bean on your Servoy form, also copy the ibizqb.jar file to "/servoy/lib".

  5. There is a jar file called "deploy.jar" in the same directory. This is the production version of the bean. When you go live, use this file instead of ibizqb.jar, placing it in the same directories as above. ibizqb.jar is a little larger and contains more debug code.

  6. The trial version of the bean has a 3-sec delay built in to every call. This will make the communication seem slow. This delay is removed when you purchase a licensed version.

  7. Quickbooks Remote Connector (allows the bean to talk to Quickbooks over an HTTP connection)

  8. Install the ibiz Quickbooks Remote Connector on the Windows machine where Quickbooks is installed

  9. After installation, find the Remote Connector program in your Start menu and launch it

  10. Start the Remote Connector by clicking on the START button

  11. Note the network name of the computer where Remote Connector is installed. You'll need this on your Servoy machine to connect

Creating a sample form in Servoy using the ibizqb bean:



  1. Open blank form and name it "beantest". It can be based on any table at this point. For the sample form, we won't actually write any data to a table

  2. Create a couple of global variable fields you can use to view data from Quickbooks and place them on this form (gTest1, gTest2)

  3. Place a button on your form to use to fire the method we'll create that talks to Quickbooks

  4. Select the button object you just created and double-click the onAction property. Create a new Method called "qbTest" and click OK. We'll get to the editor in a minute to finish the method coding

  5. Click on the Bean icon on the toolbar. It looks like a little brown coffee bean

  6. Select "Customer" from the list of available bean objects. Servoy will add an object to the form with a name like "bean_315". You'll need to note this name so you can find it under your form elements node in the Editor

  7. Click on the Editor icon on the toolbar and the editor will open

  8. The new method you created above should be open and blank in the editor (qbTest). If not, navigate to -Application/Forms/beantest and click on it, then click the "new method" icon to create a new method on our form and name it "qbTest"

Below, are two versions of qbTest that you can try. Make sure to change the method your button uses for onAction to test out the other method shown below.

Reading from Quickbooks: get a customer (copy and paste the code below into your method)

// substitute the name of your Quickbooks computer name for  
elements.bean_115.QBConnectionString = "URL='http://yoda:2080'"
elements.bean_115.openQBConnection
// Set QBRequestId to an empty string or to a unique string every time to make a call to QB.
// You can query QB with QBRequestId to see if your request was accepted, but for now we're not using it
elements.bean_115.QBRequestId = '' // this is two single quotes, representing an empty string
// Look in your existing Quickbooks customer list and find the name of a company to put in here
// this method will retrieve a customer record from QB
elements.bean_115.getByName("My Company")

// Now that we have a customer record, show the contact name on our form to prove it
// Make sure your customer actually has a contact name filled in
globals.gTest1 = elements.bean_115.contactName

Try this out by running your form and clicking on the button. If you have everything right, you should get back your contact name. If nothing happens, you will need to troubleshoot. Look for the following errors:

  1. Is your firewall blocking port 2080 on the Quickbooks machine?

  2. Did you START the remote connector on the Quickbooks machine and open Quickbooks?

  3. Did you locate the name of the Quickbooks computer and put that name in the method above in the QBConnectionString property?

  4. Does your customer have the contact name field populated with a name in Quickbooks?

Now, let's update a piece of information in Quickbooks and show that we can write to it:

elements.bean_115.QBConnectionString = "URL='http://yoda:2080'"

elements.bean_115.openQBConnection
elements.bean_115.QBRequestId = ''
elements.bean_115.getByName("My Company")
// Now that we have a customer record, let's change the altphone property in QB
elements.bean_115.altPhone = '999-999-9999'
// Write the record back to QB - WARNING: this will overwrite the Alt Phone field on this record
elements.bean_115.update()

If all went well, you're now talking to Quickbooks from Servoy with only 4-5 lines of code!

HELP Files
When you unzipped the ibiz files, it should have created a Javadoc directory. Go to this directory and open the file "index.html". In this file you will be able to lookup all the properties and methods for each class available in the bean. There are many object types you can work with in Quickbooks (i.e. payments, invoices, customers, etc) All are documented in Javadoc.

In our next article, I will describe how to utilize the ibizqb.jar objects directly, without having to use a bean on a form. This will allow you to create multiple instances of each object and put them into arrays, allowing you to do things like hold all customers in memory at once, instead of reading them one at a time.

2 comments:

Jeff Bader said...

QuickBooks is very widely used in the SMB market - it's everywhere. Unfortunately though it tends to be a bit difficult to integrate with other business systems.

Being able to use Servoy to integrate QuickBooks is really great! Looking forward to learning more about this. Great post!

Nilesh Jethwa said...

Hi,
Would it be possible to review the Quickbooks Dashboard and share your opinion

I think this would be a very useful tool for Quickbook users and can save them lot of time from running various reports

Thanks and Regards
Nilesh
http://www.infocaptor.com

Post a Comment