Quickbooks create invoice get generated invoice ID
Quickbooks create invoice get generated invoice ID
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".
-
- Devart Team
- Posts: 2420
- Joined: Wed 02 Nov 2011 09:44
Re: Quickbooks create invoice get generated invoice ID
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();
}