cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot create document from draft

Former Member
0 Kudos

Hello!

DI API version is 8.81

The problem, that I cannot create A/P Correction Invoice from Draft, I always get an error message, that CPI1.LineStatus Invalid value, what can be the problem?

Accepted Solutions (0)

Answers (3)

Answers (3)

pedro_magueija
Active Contributor
0 Kudos

Hi Gaspar,

Have you tried SaveDraftToDocument instead?


Best regards,

Pedro Magueija


View Pedro Magueija's profile on LinkedIn

Former Member
0 Kudos

Hello!

Yes, I called this command, but when I called I got unhandled exception...

My version is 8.81, if I good know this command is availablie from 8.82 version

BR

Ricsi

Former Member
0 Kudos

I've tried and this code is working.

  If oDraft.GetByKey(CInt(oRS.Fields.Item(0).Value)) Then

                        'Build the GRPO (new GRPO Obj for each GRPO Doc)

                        oGRPO = oComp.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseDeliveryNotes)

                        oGRPO.DocDate = oDraft.DocDate

                        oGRPO.DocDueDate = oDraft.DocDueDate

                        oGRPO.DiscountPercent = oDraft.DiscountPercent

                        oGRPO.CardCode = oDraft.CardCode

                        For i = 0 To oDraft.Lines.Count - 1

                            oDraft.Lines.SetCurrentLine(i)

                            oGRPO.Lines.BaseType = oDraft.Lines.BaseType

                            oGRPO.Lines.BaseEntry = oDraft.Lines.BaseEntry

                            oGRPO.Lines.BaseLine = oDraft.Lines.BaseLine

                            If i < oDraft.Lines.Count - 1 Then

                                oGRPO.Lines.Add()

                            End If

                        Next i

                        'Add the GRPO

                        iRetCode = oGRPO.Add

                        If iRetCode <> 0 Then

                            oComp.GetLastError(iRetCode, sErrMsg)

                            Log.WriteLog("Error Adding GRPO : " & sErrMsg, EventLogEntryType.Warning)

                            Return False

                        End If

                        'Kill the GRPO

                        oGRPO = Nothing

                        'Remove the Draft

                        oDraft.Remove()

                    End If

Regards,

Bry

Blog: http://my-tipss-trickss.blogspot.com/

pedro_magueija
Active Contributor
0 Kudos

Hi Gaspar,

You're right. Sorry I missed the part where you mentioned the version.

Cheers.


Best regards,

Pedro Magueija


View Pedro Magueija's profile on LinkedIn

Former Member
0 Kudos

Can you post  your source code?

Regards,

Bry

Blog: http://my-tipss-trickss.blogspot.com/

Former Member
0 Kudos

Hello Bryan!

The source code is the following

oDoc = _ocmp.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDrafts)

oDoc.DocObjectCode = SAPbobsCOM.BoObjectTypes.oCorrectionPurchaseInvoice

oRs.DoQuery("select docentry,cardcode from odrf where docentry='" & xEle.Element("ORDNUM").Value & "'")

sbaseentry = oRs.Fields.Item("docentry").Value

oDoc.GetByKey(sbaseentry)

.

.

.

.

working with the document lines. This document has 6 lines, 3 lines status are open and 3 lines status are closed

.

.

.

oDoc.Add()

BR

Ricsi

Former Member
0 Kudos

Hi, you should only get the open line status. Kindly check why the other 3 lines are already closed.

Regards,

Bry

Blog: http://my-tipss-trickss.blogspot.com/

Former Member
0 Kudos

Hello!

I am closer and closer to the solution, the invalid row error message isn't coming, but I get a new one.

-5002 Internal server occurred

BR

Ricsi

Former Member
0 Kudos

Richard,

In my experiences, -5002 errors when converting drafts into documents come often from the data that I am trying to push into the document being the incorrect type for the field. Another cause of this is that the data is actually NULL, which obviously has no type.

Without having access to your data and your full code, my suggestion to you would be to go through every field that you're trying to push into the document, and make sure that you use IsNull to convert a null value into a blank string, integer, or other applicable "NULL" type value for the field type, and also make sure that you throw all of your input values into a Convert method to force it to be the same type as we want in that field.

Here is a rough example using some of the code that you provided above:


oDoc = _ocmp.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDrafts)

oDoc.DocObjectCode = SAPbobsCOM.BoObjectTypes.oCorrectionPurchaseInvoice

oRs.DoQuery("select docentry,cardcode from odrf where docentry='" & xEle.Element("ORDNUM").Value & "'")

'DocEntry fields are Integers, so we force this value to be an integer

Dim iDocEntry AS Integer = Convert.ToInt32(oRs.Fields.Item("docentry").Value)

If iDocEntry <> 0 Then

     sbaseentry = iDocEntry

     oDoc.GetByKey(sbaseentry)

ELSE

     MsgBox("Error: DocEntry is null or zero")

END IF

Hopefully this helps.

Former Member
0 Kudos

Why don't you post your whole source code on how you post the transaction?

Regards,

Bry

Blog: http://my-tipss-trickss.blogspot.com/

Former Member
0 Kudos

Hello!

I tested it, the result is same

BR

Ricsi

Former Member
0 Kudos

Hello!

I copied the source code, what I left is not important.

BR

Ricsi

Former Member
0 Kudos

Everything is important. There might be something in the rest of the code that might be causing the issue, and we would never know it if we didn't see the code. Please post the full source code for the procedure so that we have the full context of what you're doing.

former_member185682
Active Contributor
0 Kudos

Hi Richard,

What is the status of the line?

Regards,

Diego

Former Member
0 Kudos

Hello!

This line status is bost_Open

BR

Richard

former_member185682
Active Contributor
0 Kudos

Richard,

I tryed simulate the problem, but my localization doesn't have Correction invoice.

Maybe someone else in this board have some idea about this situation.

Good Luck

Regards,

Diego