Author Topic: InvoiceAdd  (Read 2379 times)

mikedbell

  • Member
  • *
  • Posts: 7
InvoiceAdd
« on: October 22, 2013, 12:53:37 PM »
I have a client who normally enters an invoice in QB Enterprise 12 by starting with the Customer Name and the Job Name separated by a colon. QB asks if they want to use the short cut to enter a new Customer/Job and they reply "yes". Then they enter the line items. Now they want to automate that same process using FM Books Connector. Is this possible?

Please Advise.

Mike Bell

Geoffrey Gerhard

  • Guru
  • Member
  • ****
  • Posts: 470
Re: InvoiceAdd
« Reply #1 on: October 22, 2013, 04:53:09 PM »
It's possible to add a Customer record, add a Job attached to that Customer record, and then add an Invoice for that Customer/Job, but the process is different via the API than via the UI. You can't Add an Invoice to a Job via the API until the Job exists, and you can't attach a Job to Customer via the API until the Customer exists. You'll need to make a separate Request for each record.

There are a lot of things to learn when you want a tight integration between a FileMaker solution and a QB Company file, but you can do almost anything via the API that you can do via the UI. And some things are available via the API that are unavailable via the UI.

HTH!

Geoffrey Gerhard
Creative Solutions Incorporated
14000 Creekside Drive
Matthews, NC  28105
704) 814-6852

mikedbell

  • Member
  • *
  • Posts: 7
Re: InvoiceAdd
« Reply #2 on: October 31, 2013, 08:27:15 AM »
Thanks for your reply! I've got it going now.

I have another challenge. I'm adding a shipping line to an existing invoice by using InvoiceLineMod with a TxnID of -1. I can successfully push the line but it seems to wipe out an existing line in the target invoice.

Any idea what I might be doing wrong?

Thanks Again!

MBell

Geoffrey Gerhard

  • Guru
  • Member
  • ****
  • Posts: 470
Re: InvoiceAdd
« Reply #3 on: October 31, 2013, 09:49:41 AM »
I don't remember that you need to reiterate all existing lines when modifying an Invoice Txn by adding one or more InvoiceLines, but I don't often include Txn Mod Requests in integrations and my recollection may be faulty.

When you say it wipes out an existing line, do you mean that when there is more than one InvoiceLines, it wipes out only one? Or are your Invoices only one line?

It's good practice to write an InvoiceQueryRequest to make sure you have an up-to-date EditSequence when building your InvoiceModRequest, and you can gather all the InvoiceLine detail you'll need from that Response. If it turns out that you have multiple existing InvoiceLines and need to include all of them in your InvoiceModRequest, you'll probably need to Loop through the InvoiceLineRet iterations and write your new InvoiceLineMod iterations from those values. (I say "probably" because parsing them all as a single block and using Substitute to replace "Ret>" with "Mod>" might be feasible.)

HTH!

Geoffrey Gerhard
Creative Solutions Incorporated
14000 Creekside Drive
Matthews, NC  28105
704) 814-6852

mikedbell

  • Member
  • *
  • Posts: 7
Re: InvoiceAdd
« Reply #4 on: October 31, 2013, 11:44:32 AM »
It actually wipes out all lines. I'm not sure I understand what you mean by...

"and you can gather all the InvoiceLine detail you'll need from that Response. If it turns out that you have multiple existing InvoiceLines and need to include all of them in your InvoiceModRequest, you'll probably need to Loop through the InvoiceLineRet iterations and write your new InvoiceLineMod iterations from those values."

I'll need to think that one through since I'm a newbie to this FM Connector world.

Thanks for your advise.

MBell

Geoffrey Gerhard

  • Guru
  • Member
  • ****
  • Posts: 470
Re: InvoiceAdd
« Reply #5 on: October 31, 2013, 12:03:24 PM »
I presume you're keeping track of the Invoice's TxnID that QB returns in the InvoiceAddResponse. If so, an InvoiceQueryRequest for that TxnID should also include an IncludeLineItems value of "true" to produce a Response that includes not only the EditSequence but also the details of every InvoiceLine for that Invoice. You can then use the PCQB_RsGetAttribute ( AttributeName ) function to get the Value parameter for the corresponding PCQB_RqAddFieldWithValue ( QBFieldName ; Value ; optAttributes ) function in the InvoiceModRequest.

HTH!

Geoffrey Gerhard
Creative Solutions Incorporated
14000 Creekside Drive
Matthews, NC  28105
704) 814-6852

mikedbell

  • Member
  • *
  • Posts: 7
Re: InvoiceAdd
« Reply #6 on: November 05, 2013, 11:38:51 AM »
So, if I read your post correctly, PCQB_GetAttribute will return real info instead of *Still under development* like the Functions Guide says?

Geoffrey Gerhard

  • Guru
  • Member
  • ****
  • Posts: 470
Re: InvoiceAdd
« Reply #7 on: November 05, 2013, 12:43:44 PM »
I believe it does but I've never used it because I learned to apply XPATH filters long ago, and they are substantially more powerful tools. That said, I copy/pasted the wrong function in my previous reply. Sorry for the confusion.

The PCQB_RsGetFirstFieldValue( QBFieldName ) function, in conjunction PCQB_RsOpenFirstRelatedRecord ( "InvoiceLineRet" ) and PCQB_RsOpenNextRelatedRecord, will allow you to pull all the data you need to identify the existing Invoice LineItems. Once the InvoiceLineRet is identified by one of the latter, I believe you can use...

Let ( [
QBFieldName = "TxnLineID"
] ;

PCQB_RqAddFieldWithValue ( QBFieldName ; PCQB_RsGetFirstFieldValue( QBFieldName ) ; "" )

)

...to add the correct InvoiceLine TxnLineID value to your InvoiceModRequest. I say "I believe you can" because I do it differently and haven't tested that construction.

HTH!

Geoffrey Gerhard
Creative Solutions Incorporated
14000 Creekside Drive
Matthews, NC  28105
704) 814-6852