cancel
Showing results for 
Search instead for 
Did you mean: 

Add draft line through DI

Former Member
0 Kudos

Hi Expert,

Where should I put the vDrafts.Lines.Add?

we need to put the "vDrafts.Lines.Add" But it is not need for the 1st line.

rstGRA1 is the recordset of the line detail

rstGRA1.MoveFirst

Do While Not rstGRA1.EOF

vDrafts.Lines.ItemCode = rstGRA1.Fields("U_Itemcode")

vDrafts.Lines.Quantity = rstGRA1.Fields("Quantity")

rstGRA1.MoveNext

Loop

Thanks a lot

Best regards

Gary

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Got it

thanks

Former Member
0 Kudos

I use following code, but it seems to be have a better solution. Could you please rewrite it. Thanks a lot

'draft line - set values to the first line

rstGRA1.MoveFirst

If Not rstGRA1.EOF Then

vDrafts.Lines.ItemCode = rstGRA1.Fields("U_Itemcode")

vDrafts.Lines.Quantity = rstGRA1.Fields("Quantity")

vDrafts.Lines.UnitPrice = rstGRA1.Fields("price")

End If

'For ongoing line

rstGRA1.MoveNext

Do While Not rstGRA1.EOF

vDrafts.Lines.Add

vDrafts.Lines.ItemCode = rstGRA1.Fields("U_Itemcode")

vDrafts.Lines.Quantity = rstGRA1.Fields("Quantity")

vDrafts.Lines.UnitPrice = rstGRA1.Fields("price")

rstGRA1.MoveNext

Loop

Johan_H
Active Contributor
0 Kudos

Hi Gary,

Is this code not working properly ? It looks fine to me.

Regards,

Johan

Former Member
0 Kudos

Hi Johan

Yes! The code can work , but not good enough to maintance.

It is necessary to add two parts(1st row and ongoing row) for every control .

I have more than 30 controls, then I need to add 60 lines in it.

Is it the only way?

Thanks

Gary

Johan_H
Active Contributor
0 Kudos

Hi Gary,

It depends a bit, on the source type of your data, but the general idea is to keep count of the rows, and add a new line only if another row is forthcoming.

The SDK's own example uses a DataTable (DataGrid)


Dim i As Integer
        i = 0

Do
     oOrder.Lines.ItemCode = TableLines.Rows(i).Item(0)
     oOrder.Lines.ItemDescription = TableLines.Rows(i).Item(1)
     oOrder.Lines.Quantity = TableLines.Rows(i).Item(2)
     oOrder.Lines.Price = TableLines.Rows(i).Item(3)
     oOrder.Lines.TaxCode = TableLines.Rows(i).Item(4)
     oOrder.Lines.LineTotal = TableLines.Rows(i).Item(5)

     i += 1
     If i <> TableLines.Rows.Count Then
            oOrder.Lines.Add()
     End If
Loop Until i = TableLines.Rows.Count

I use a DataSet myself:


'Doc is a B1 order object
With Doc
          For Each rw As DataRow In MyDataSet.Tables("TableName").Rows
                        .Lines.ItemCode = rw.Item(cn_ItemCode)
                        .Lines.Quantity = rw.Item(cn_Quantity)
                        .Lines.Price = rw.Item(cn_Price)
                        .Lines.UserFields.Fields.Item("U_CustLineNum").Value = rw.Item(cn_LineNum)

                        'SBO creates the first row automatically.
                        'Add a new row only if necessary
                        If _Rows.Rows.IndexOf(rw) < _Rows.Rows.Count Then .Lines.Add()
          Next
End With

See if you can do something with this.

Good luck,

Johan

Edited by: Johan Hakkesteegt on Feb 23, 2012 8:39 AM

Answers (2)

Answers (2)

Former Member
0 Kudos

looking for rewrite

Former Member
0 Kudos

I got it thanks