cancel
Showing results for 
Search instead for 
Did you mean: 

sales order

Former Member
0 Kudos

Hi Experts,

i have a text file in the following format

H01...

D01

D01

D01

H01

D01

H01

i have my code to create a sales order

for (int i = 0; i < lines.Length; i++)

{

line = lines<i>;

if (line.Substring(0, 3).Contains("H01"))

{

oSalesOrder.CardCode = line.Substring(26, 15).Trim()

oSalesOrder.NumAtCard = line.Substring(3, 9).Trim();

oSalesOrder.DocDueDate = Convert.ToDateTime("12/21/07");

oSalesOrder.TaxDate = Convert.ToDateTime("12/21/07");

}

if (line.Substring(0, 3).Contains("D01"))

{

oSalesOrder.Lines.ItemCode = line.Substring(22, 256).Trim();

oSalesOrder.Lines.Quantity = System.Convert.ToDouble(line.Substring(278, 20));

oSalesOrder.Lines.UnitPrice = System.Convert.ToDouble(line.Substring(298, 20));

oSalesOrder.Lines.Add();

}

else

{

i++;

}

result = oSalesOrder.Add();

if (result != 0)

{

System.Windows.Forms.MessageBox.Show(oCompany.GetLastErrorDescription());

}

else

{

System.Windows.Forms.MessageBox.Show("Sales Order added!");

}

}

I am not able to create a sales order for multiple detail records using this logic. could anyone advise me on the same.

Thanks and Regards,

Kreddy.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi

If u want to add multiple row in your sales order then take care that

"oSalesOrder.Lines.Add();" this line should not executed for more than the no of rows you are going to add minus 1 .Bcoz first row do not require this line

I am sendin u an snapshot of my code

here i have an recordset as RS I got some record in it

and I have created an document of goods Receipt PO in which I added the the rows from recordset

At that time I checked that no extra line is to be get added

RS.DoQuery("SELECT U_ItemCode,U_ItemName,U_TaxCode,U_DelDate,U_GLAccNo,U_OProdOrd,U_salesOrd,U_PrjCode,U_ItemDtl,U_Qty,U_UnitPrc,U_Disc,U_SubWhrs FROM [@OSPOCHRG] WHERE DocEntry =" & GRPODocNum & " ")

While RS.EoF = False

For j = 0 To Struct_GRCHRGITM1.Length - 1

If RS.Fields.Item("U_ItemCode").Value = Struct_GRCHRGITM1(j).ItemNo Then

GrPODoc.Lines.ItemCode = RS.Fields.Item("U_ItemCode").Value

GrPODoc.Lines.AccountCode = RS.Fields.Item("U_GLAccNo").Value

GrPODoc.Lines.WarehouseCode = RS.Fields.Item("U_SubWhrs").Value

GrPODoc.Lines.Quantity = Struct_GRCHRGITM1(j).ReqQtyfor_OnePiece * GRMatQty

GrPODoc.Lines.UnitPrice = RS.Fields.Item("U_UnitPrc").Value

GrPODoc.Lines.DiscountPercent = RS.Fields.Item("U_Disc").Value

GrPODoc.Lines.TaxCode = RS.Fields.Item("U_TaxCode").Value

End If

Next

If i <> RS.RecordCount - 1 Then'If this last record in recordset then do not add extra line

GrPODoc.Lines.Add()

End If

i = i + 1

RS.MoveNext()

End While

val = GrPODoc.Add

Gr_POObjectType = GrPODoc.DocObjectCode 'Sets or returns a valid value of BoObjectTypes type that specifies the object type related to doc

GR_PODocentry = ocompany.GetNewObjectKey() 'Retrieves the key/DocNo. of the last added record.

If val <> 0 Then

ocompany.GetLastError(ErrCode, ErrMsg)

SBOApplication.MessageBox(ErrCode & "," & ErrMsg)

hope it will help u

Answers (0)