Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Inserting Multiple InvlineItems into QB

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Inserting Multiple InvlineItems into QB

    The code shown below is designed to enter an invoice with 11 Line Items into QBES V8. The table "multi_invoices" is filtered by refnumber 2811 and is sorted so that "Fqsavetocache" is set to 1 for the first 10 records and 0 for the last record. When I run the code I get 11 "Record was created" messages and no errors, but when I look at the invoice in QBES it shows one invoice with 1 line item - the last one in the series.
    The following quote is directly from the QODBC Forum:

    "Multi-line invoices require a series of SQL statements to complete a single invoice. In the example below we are creating a 3 line invoice using 3 SQL INSERT commands in sequence. The key to this process is the field named "FQSaveToCache". This field is not part of the table, but is used as a flag to the QODBC driver. In the sequence below, you should note that the value of "FQSaveToCache" is set to 1 or TRUE for the first two line item insert statements, and then it is set to 0 or FALSE for the final statement.

    A TRUE setting of "FQSaveToCache" instructs QODBC to take the values from your INSERT statement and hold them for later processing, but not to save them to QuickBooks yet. When QODBC receives the final transaction where the cache is set to 0 or FALSE, the contents of the current INSERT statement will be combined with all of the previous INSERT statements held in the cache for this connection, and saved as a batch into QuickBooks.
    "

    It seems to me that my code adheres to the method described above
    I would really appreciate it if someone could please show me what I'm doing wrong here.

    THANKS
    JAS

    Code:
    code = UI_YES_NO+UI_ATTENTION_SYMBOL + UI_SECOND_BUTTON_DEFAULT
    result = ui_msg_box("","This action will EXPORT ALL OPEN INVOICES QBES. CONTINUE?",code)
    IF result = UI_NO_SELECTED THEN
    	goto finish2
    	end
    END IF
    
    Dim Shared  vCustomerreflistid as C
    Dim Shared  vCustomerreffullname as C
    Dim Shared  vTxndate as D
    Dim Shared  vRefnumber as C
    Dim Shared  vBilladdressaddr1 as C
    Dim Shared  vBilladdressaddr2 as C
    Dim Shared  vBilladdressaddr3 as C
    Dim Shared  vBilladdressaddr4 as C
    Dim Shared  vBilladdressaddr5 as C
    Dim Shared  vBilladdresscity as C
    Dim Shared  vBilladdressstate as C
    Dim Shared  vBilladdresspostalcode as C
    Dim Shared  vBilladdresscountry as C
    Dim Shared  vShipaddressaddr1 as C
    Dim Shared  vShipaddressaddr2 as C
    Dim Shared  vShipaddressaddr3 as C
    Dim Shared  vShipaddressaddr4 as C
    Dim Shared  vShipaddressaddr5 as C
    Dim Shared  vShipaddresscity as C
    Dim Shared  vShipaddressstate as C
    Dim Shared  vShipaddresspostalcode as C
    Dim Shared  vShipaddresscountry as C
    Dim Shared  vInvoicelineitemreflistid as C
    Dim Shared  vInvoicelineitemreffullname as C
    Dim Shared  vInvoicelinedesc as C
    Dim Shared  vInvoicelinequantity as N
    Dim Shared  vInvoicelinerate as N
    Dim Shared  vInvoicelineamount as N
    Dim Shared  vFqsavetocache as N
    dim total_records as N
    dim iterations as N = 0
    
    dim t as p
    t=table.open("multi_invoices")
    query.order="Txnid+Cache_order"
    query.filter="refnumber=\"2811\""
    indx=t.query_create()
    total_records =indx.records_get()
    t.fetch_first()
    WHILE .not. t.fetch_eof()
    	iterations = iterations + 1
    	statusbar.SET_text("Working - records processed: " + alltrim(str(iterations,5,0))+" of"+alltrim(str(total_records,5,0)))
    
    	vCustomerreflistid = t.CUSTOMERMSGREFLISTID
    	vCustomerreffullname  = t.CUSTOMERREFFULLNAME
    	vTxndate  = t.TXNDATE
    	vRefnumber  = t.REFNUMBER
    	vBilladdressaddr1  = t.BILLADDRESSADDR1
    	vBilladdressaddr2  = t.BILLADDRESSADDR2
    	vBilladdressaddr3  = t.BILLADDRESSADDR3
    	vBilladdressaddr4  = t.BILLADDRESSADDR4
    	vBilladdressaddr5  = t.BILLADDRESSADDR5
    	vBilladdresscity  = t.Billaddresscity
    	vBilladdressstate  = t.Billaddressstate
    	vBilladdresspostalcode  = t.Billaddresspostalcode
    	vBilladdresscountry  = t.Billaddresscountry
    	vShipaddressaddr1  = t.SHIPADDRESSADDR1
    	vShipaddressaddr2  = t.SHIPADDRESSADDR2
    	vShipaddressaddr3  = t.SHIPADDRESSADDR3
    	vShipaddressaddr4  = t.SHIPADDRESSADDR4
    	vShipaddressaddr5  = t.SHIPADDRESSADDR5
    	vShipaddresscity  = t.Shipaddresscity
    	vShipaddressstate  = t.Shipaddressstate
    	vShipaddresspostalcode  = t.Shipaddresspostalcode
    	vShipaddresscountry  = t.Shipaddresscountry
    	vInvoicelineitemreflistid  = t.Invoicelineitemreflistid
    	vInvoicelineitemreffullname  = t.Invoicelineitemreffullname
    	vInvoicelinedesc  = t.Invoicelinedesc
    	vInvoicelinequantity  = t.Invoicelinequantity
    	vInvoicelinerate  = t.Invoicelinerate
    	vInvoicelineamount  = t.Invoicelineamount
    	vFqsavetocache  = t.FQSAVETOCACHE
    		
    	'Insert a new record into a remote SQL database.
    	'DIM a connection variable
    	DIM cn as SQL::Connection
    	dim flagResult as l
    	flagResult = cn.open("::Name::QB_Test")
    	IF flagResult = .f. THEN
    		ui_msg_box("Error","Could not connect to database. Error reported was: " + crlf() + cn.CallResult.text)
    		end
    	END IF
    	
    	'Specify that we are using Portable SQL syntax
    	cn.PortableSQLEnabled = .t.
    	
    	'Dim a SQL arguments object, create arguments and set their values
    	DIM args as sql::arguments
    	
    	IF a5_eval_valid_expression("=Var->vCustomerreflistid",local_variables()) THEN
    		args.add("CustomerRefListID",convert_type(a5_eval_expression("=Var->vCustomerreflistid",local_variables()),"C"))
    	END IF
    	IF a5_eval_valid_expression("=Var->vCustomerreffullname",local_variables()) THEN
    		args.add("CustomerRefFullName",convert_type(a5_eval_expression("=Var->vCustomerreffullname",local_variables()),"C"))
    	END IF
    	IF a5_eval_valid_expression("=Var->vTxndate",local_variables()) THEN
    		args.add("TxnDate",convert_type(a5_eval_expression("=Var->vTxndate",local_variables()),"D"))
    	END IF
    	IF a5_eval_valid_expression("=Var->vRefnumber",local_variables()) THEN
    		args.add("RefNumber",convert_type(a5_eval_expression("=Var->vRefnumber",local_variables()),"C"))
    	END IF
    	IF a5_eval_valid_expression("=Var->vBilladdressaddr1",local_variables()) THEN
    		args.add("BillAddressAddr1",convert_type(a5_eval_expression("=Var->vBilladdressaddr1",local_variables()),"C"))
    	END IF
    	IF a5_eval_valid_expression("=Var->vBilladdressaddr2",local_variables()) THEN
    		args.add("BillAddressAddr2",convert_type(a5_eval_expression("=Var->vBilladdressaddr2",local_variables()),"C"))
    	END IF
    	IF a5_eval_valid_expression("=Var->vBilladdressaddr3",local_variables()) THEN
    		args.add("BillAddressAddr3",convert_type(a5_eval_expression("=Var->vBilladdressaddr3",local_variables()),"C"))
    	END IF
    	IF a5_eval_valid_expression("=Var->vBilladdressaddr4",local_variables()) THEN
    		args.add("BillAddressAddr4",convert_type(a5_eval_expression("=Var->vBilladdressaddr4",local_variables()),"C"))
    	END IF
    	IF a5_eval_valid_expression("=Var->vBilladdressaddr5",local_variables()) THEN
    		args.add("BillAddressAddr5",convert_type(a5_eval_expression("=Var->vBilladdressaddr5",local_variables()),"C"))
    	END IF
    	IF a5_eval_valid_expression("=Var->vBilladdresscity",local_variables()) THEN
    		args.add("BillAddressCity",convert_type(a5_eval_expression("=Var->vBilladdresscity",local_variables()),"C"))
    	END IF
    	IF a5_eval_valid_expression("=Var->vBilladdressstate",local_variables()) THEN
    		args.add("BillAddressState",convert_type(a5_eval_expression("=Var->vBilladdressstate",local_variables()),"C"))
    	END IF
    	IF a5_eval_valid_expression("=Var->vBilladdresspostalcode",local_variables()) THEN
    		args.add("BillAddressPostalCode",convert_type(a5_eval_expression("=Var->vBilladdresspostalcode",local_variables()),"C"))
    	END IF
    	IF a5_eval_valid_expression("=Var->vBilladdresscountry",local_variables()) THEN
    		args.add("BillAddressCountry",convert_type(a5_eval_expression("=Var->vBilladdresscountry",local_variables()),"C"))
    	END IF
    	IF a5_eval_valid_expression("=Var->vShipaddressaddr1",local_variables()) THEN
    		args.add("ShipAddressAddr1",convert_type(a5_eval_expression("=Var->vShipaddressaddr1",local_variables()),"C"))
    	END IF
    	IF a5_eval_valid_expression("=Var->vShipaddressaddr2",local_variables()) THEN
    		args.add("ShipAddressAddr2",convert_type(a5_eval_expression("=Var->vShipaddressaddr2",local_variables()),"C"))
    	END IF
    	IF a5_eval_valid_expression("=Var->vShipaddressaddr3",local_variables()) THEN
    		args.add("ShipAddressAddr3",convert_type(a5_eval_expression("=Var->vShipaddressaddr3",local_variables()),"C"))
    	END IF
    	IF a5_eval_valid_expression("=Var->vShipaddressaddr4",local_variables()) THEN
    		args.add("ShipAddressAddr4",convert_type(a5_eval_expression("=Var->vShipaddressaddr4",local_variables()),"C"))
    	END IF
    	IF a5_eval_valid_expression("=Var->vShipaddressaddr5",local_variables()) THEN
    		args.add("ShipAddressAddr5",convert_type(a5_eval_expression("=Var->vShipaddressaddr5",local_variables()),"C"))
    	END IF
    	IF a5_eval_valid_expression("=Var->vShipaddresscity",local_variables()) THEN
    		args.add("ShipAddressCity",convert_type(a5_eval_expression("=Var->vShipaddresscity",local_variables()),"C"))
    	END IF
    	IF a5_eval_valid_expression("=Var->vShipaddressstate",local_variables()) THEN
    		args.add("ShipAddressState",convert_type(a5_eval_expression("=Var->vShipaddressstate",local_variables()),"C"))
    	END IF
    	IF a5_eval_valid_expression("=Var->vShipaddresspostalcode",local_variables()) THEN
    		args.add("ShipAddressPostalCode",convert_type(a5_eval_expression("=Var->vShipaddresspostalcode",local_variables()),"C"))
    	END IF
    	IF a5_eval_valid_expression("=Var->vShipaddresscountry",local_variables()) THEN
    		args.add("ShipAddressCountry",convert_type(a5_eval_expression("=Var->vShipaddresscountry",local_variables()),"C"))
    	END IF
    	IF a5_eval_valid_expression("=Var->vInvoicelineitemreflistid",local_variables()) THEN
    		args.add("InvoiceLineItemRefListID",convert_type(a5_eval_expression("=Var->vInvoicelineitemreflistid",local_variables()),"C"))
    	END IF
    	IF a5_eval_valid_expression("=Var->vInvoicelineitemreffullname",local_variables()) THEN
    		args.add("InvoiceLineItemRefFullName",convert_type(a5_eval_expression("=Var->vInvoicelineitemreffullname",local_variables()),"C"))
    	END IF
    	IF a5_eval_valid_expression("=Var->vInvoicelinedesc",local_variables()) THEN
    		args.add("InvoiceLineDesc",convert_type(a5_eval_expression("=Var->vInvoicelinedesc",local_variables()),"M"))
    	END IF
    	IF a5_eval_valid_expression("=Var->vInvoicelinequantity",local_variables()) THEN
    		args.add("InvoiceLineQuantity",convert_type(a5_eval_expression("=Var->vInvoicelinequantity",local_variables()),"N"))
    	END IF
    	IF a5_eval_valid_expression("=Var->vInvoicelinerate",local_variables()) THEN
    		args.add("InvoiceLineRate",convert_type(a5_eval_expression("=Var->vInvoicelinerate",local_variables()),"N"))
    	END IF
    	IF a5_eval_valid_expression("=Var->vInvoicelineamount",local_variables()) THEN
    		args.add("InvoiceLineAmount",convert_type(a5_eval_expression("=Var->vInvoicelineamount",local_variables()),"N"))
    	END IF
    	IF a5_eval_valid_expression("=Var->vFqsavetocache",local_variables()) THEN
    		args.add("FQSaveToCache",convert_type(a5_eval_expression("=Var->vFqsavetocache",local_variables()),"N"))
    	END IF
    	
    	
    	dim sqlInsertStatement as c
    	sqlInsertStatement = <<%txt%
    INSERT INTO InvoiceLine  (CustomerRefListID, CustomerRefFullName, TxnDate, RefNumber, BillAddressAddr1, BillAddressAddr2, BillAddressAddr3, BillAddressAddr4, BillAddressAddr5, BillAddressCity, BillAddressState, BillAddressPostalCode, BillAddressCountry, ShipAddressAddr1, ShipAddressAddr2, ShipAddressAddr3, ShipAddressAddr4, ShipAddressAddr5, ShipAddressCity, ShipAddressState, ShipAddressPostalCode, ShipAddressCountry, Invoicelineitemreflistid, Invoicelineitemreffullname,InvoiceLineDesc, InvoiceLineQuantity, InvoiceLineRate, InvoiceLineAmount, FQSaveToCache) VALUES (:CustomerRefListID, :CustomerRefFullName, :TxnDate, :RefNumber, :BillAddressAddr1, :BillAddressAddr2, :BillAddressAddr3, :BillAddressAddr4, :BillAddressAddr5, :BillAddressCity, :BillAddressState, :BillAddressPostalCode, :BillAddressCountry, :ShipAddressAddr1, :ShipAddressAddr2, :ShipAddressAddr3, :ShipAddressAddr4, :ShipAddressAddr5, :ShipAddressCity, :ShipAddressState, :ShipAddressPostalCode, :ShipAddressCountry, :Invoicelineitemreflistid, :Invoicelineitemreffullname, :InvoiceLineDesc, :InvoiceLineQuantity, :InvoiceLineRate, :InvoiceLineAmount, :FQSaveToCache)
    %txt%
    	dim flag as l
    	flag = cn.Execute(sqlInsertStatement,args)
    
    	IF flag = .f. THEN
    		ui_msg_box("Error","Record was not inserted. Error reported was: " + crlf(2) + cn.CallResult.text,UI_STOP_SYMBOL)
    	ELSE
    		IF cn.AffectedRows() = 1 THEN
    			'ui_msg_box("Notice","Record was created.",UI_INFORMATION_SYMBOL)
    		ELSE
    			ui_msg_box("Error","Record was not inserted." ,UI_STOP_SYMBOL)
    		END IF
    	END IF
    	
    	'Now, close the connection
    	cn.close()
    	t.fetch_next()
    END WHILE
    finish:
    indx.drop()
    t.close()
    ui_msg_box("","Operation Complete!")
    
    END
    finish2:
    
    ui_msg_box("","Operation Cancelled!")

    #2
    Re: Inserting Multiple InvlineItems into QB

    James

    Merry Christmas...

    I've usually added all of the invoice lines and then added the invoice record as the last entry.

    It looks to me like you are trying to add the header with the lines... I know that the header is there when the invoiceline is read, but try adding just the lines and then the invoice table as the last entry...

    I think there are examples in the QODBC forum..
    Al Buchholz
    Bookwood Systems, LTD
    Weekly QReportBuilder Webinars Thursday 1 pm CST

    Occam's Razor - KISS
    Normalize till it hurts - De-normalize till it works.
    Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
    When we triage a problem it is much easier to read sample systems than to read a mind.
    "Make it as simple as possible, but not simpler."
    Albert Einstein

    http://www.iadn.com/images/media/iadn_member.png

    Comment


      #3
      Re: Inserting Multiple InvlineItems into QB

      Thanks Al:
      I did as you suggested and am now getting the following error:
      see attached.

      Merry Christmas and Happy New Year to you and yours,
      Jas

      Comment


        #4
        Re: Inserting Multiple InvlineItems into QB

        Al:
        I finally figured out what I was doing wrong. I was opening and closing the QB connection with each line item. So I opened a connection before doing anything else, stepped thru all the line items and then closed the connection after the final line item (containing header information) and it worked!

        Thanks again
        Jas

        Comment


          #5
          Re: Inserting Multiple InvlineItems into QB

          Originally posted by jas View Post
          Al:
          I finally figured out what I was doing wrong. I was opening and closing the QB connection with each line item. So I opened a connection before doing anything else, stepped thru all the line items and then closed the connection after the final line item (containing header information) and it worked!

          Thanks again
          Jas
          James

          Good point. Sorry I missed that. I've had that happen too....

          Merry Christmas...
          Al Buchholz
          Bookwood Systems, LTD
          Weekly QReportBuilder Webinars Thursday 1 pm CST

          Occam's Razor - KISS
          Normalize till it hurts - De-normalize till it works.
          Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
          When we triage a problem it is much easier to read sample systems than to read a mind.
          "Make it as simple as possible, but not simpler."
          Albert Einstein

          http://www.iadn.com/images/media/iadn_member.png

          Comment

          Working...
          X