on 02-20-2017 2:59 PM
Hello
I'm developing an addon to create three sales orders at once. The lErrCode var is returning value -5002 but the method GetLastError isn't returning any code/message. My code is as follow and the output is a message box written C:0 M: (error code 0 and no message).
PS: I'm sure all the oOrder vars are being filled properly. I've run a few debugs to print their values.
private void addOrder(int docNum, string numero, int packs, double preco)
{
// Init the Order object
SAPbobsCOM.Documents oOrder;
oOrder = (SAPbobsCOM.Documents)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oOrders);
// set properties of the Order object
oOrder.CardCode = lastOrder.CardCode;
oOrder.CardName = lastOrder.CardName;
oOrder.Address = lastOrder.Address;
oOrder.Address2 = lastOrder.Address2;
oOrder.ContactPersonCode = Int32.Parse(ComboBox0.Selected.Value);
oOrder.NumAtCard = numero;
oOrder.HandWritten = SAPbobsCOM.BoYesNoEnum.tNO;
oOrder.DocNum = docNum;
oOrder.DocDate = DateTime.Today;
oOrder.DocDueDate = Convert.ToDateTime(oForm.DataSources.UserDataSources.Item("UD_0").Value);
oOrder.TaxDate = Convert.ToDateTime(oForm.DataSources.UserDataSources.Item("UD_1").Value);
oOrder.DocCurrency = lastOrder.DocCurrency;
oOrder.GroupNumber = lastOrder.GroupNumber;
oOrder.PaymentMethod = lastOrder.PaymentMethod;
oOrder.DiscountPercent = 10;
oOrder.TaxExtension.MainUsage = lastOrder.TaxExtension.MainUsage;
oOrder.TaxExtension.TaxId0 = lastOrder.TaxExtension.TaxId0;
oOrder.TaxExtension.TaxId1 = lastOrder.TaxExtension.TaxId1;
// Add lines to the Orer object from the table
int i;
double q, tot;
tot = 0;
i = 1;
do
{
Matrix0.GetLineData(i);
q = System.Convert.ToDouble(oForm.DataSources.UserDataSources.Item("UD_Matrix").Value) * packs;
oOrder.Lines.ItemCode = EditText0.Value;
oOrder.Lines.ItemDescription = sDescription;
oOrder.Lines.SupplierCatNum = Matrix0.Columns.Item(1).Cells.Item(i).Specific.ToString();
oOrder.Lines.Quantity = q;
oOrder.Lines.Price = preco;
oOrder.Lines.Usage = lastOrder.TaxExtension.MainUsage.ToString();
oOrder.Lines.TaxCode = "IMP0001";
oOrder.Lines.LineTotal = q * preco;
tot += preco * q;
if (i != Matrix0.RowCount)
{
oOrder.Lines.Add();
}
i++;
} while (i <= Matrix0.RowCount);
//oOrder.DiscountPercent = bpDiscount;
int lRetCode = oOrder.Add(); // Try to add the orer to the database
int lErrCode = 0;
string sErrMsg = "";
if (lRetCode != 0)
{
int temp_int = lErrCode;
string temp_string = sErrMsg;
oCompany.GetLastError(out temp_int, out temp_string);
if (lErrCode != -4006) // Incase adding an order failed
{
Application.SBO_Application.MessageBox("C:" + lErrCode + " M:" + sErrMsg); // Display error message
}
}
else
{
Application.SBO_Application.MessageBox("Order Added to DataBase");
}
}
Hi Rudá,
In your code, you can set the error message to the variable temp_string, what is the value in temp_string and temp_int
oCompany.GetLastError(out temp_int, out temp_string);
You can simplify your code like this:
int lRetCode = oOrder.Add();
if(lRetCode != 0)
{
if (lRetCode != -4006)
{
Application.SBO_Application.MessageBox("C:" + oCompany.GetLastErrorCode() + " M:" + oCompany.GetLastErrorDescription()); // Display error message
}
}
else
{
Application.SBO_Application.MessageBox("Order Added to DataBase");
}
Hope it helps.
Kind Regards,
Diego Lother
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
107 | |
12 | |
11 | |
6 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.