Page 1 of 1
Quickbooks create invoice get generated invoice ID
Posted: Mon 01 Oct 2018 18:25
by tklawsuc
I'm using QuickBooksCommand to create an invoice. How do I get the DocNumber and Id from the generated invoice? I tried using parameters with direction set to output but this fails with "Specified method not supported".
Re: Quickbooks create invoice get generated invoice ID
Posted: Tue 02 Oct 2018 14:50
by Pinturiccio
You need to add "RETURNING Id, DocNumber" at the end of insert query and read these values via QuickBooksDataReader. Here an example of simple Windows Forms application:
Code: Select all
public Form1()
{
InitializeComponent();
quickBooksConnection1.Open();
QuickBooksCommand comm = quickBooksConnection1.CreateCommand();
comm.CommandText = @"INSERT INTO Invoice (DocNumber, Line, CustomerRefId) VALUES (NULL, '[
{
""Amount"": 0,
""Description"": ""Custom Devices"",
""DetailType"": ""SalesItemLineDetail"",
""SalesItemLineDetail_ItemRefId"": ""5"",
""SalesItemLineDetail_ItemRefName"": ""60"",
""SalesItemLineDetail_Qty"": 1.0
}
]', '9') RETURNING Id, DocNumber";
QuickBooksDataReader reader = comm.ExecuteReader();
reader.Read();
MessageBox.Show("New invoice Id = " + reader.GetValue("Id").ToString());
MessageBox.Show("New invoice DocNumber = " + reader.GetValue("DocNumber").ToString());
quickBooksConnection1.Close();
}