cancel
Showing results for 
Search instead for 
Did you mean: 

How to check if SAPbobsCOM.Documents object represents draft?

0 Kudos
1,209

Hi folks,

I get the draft invoice in this way:

SAPbobsCOM.Documents oDoc = Company.GetBusinessObject( SAPbobsCOM.BoObjectTypes.oDrafts );
oDoc.GetByKey( docEntry );

Now, I want to check if object oDoc represetns draft or regular document.

After method GetByKey() property DocObjectCodeEx (and DocObjectCode too) return value 13 (and oInvoice).

m_felicella
Participant

Accepted Solutions (0)

Answers (3)

Answers (3)

vitor_vieira
Explorer
0 Kudos

Hi Przemyslaw,

You might still get a false positive i.e. there is actually a draft with the same DocEntry for the same DocType.

If the Draft is found I would also check if the BP codes and DocNum's match. This should reduce the probability of getting false positives.

Regards,

VV

vitor_vieira
Explorer
0 Kudos

Hi Przemyslaw,

I see the issue. Never came across this scenario myself.

Do you at least know if all the documents are based on a Draft? If they do, you can use the 'draftkey' property to distinguish the - all Drafts have draftkey = -1 and all documents based on a draft will have a value other than -1. Again, this logic will only work if you know for sure all the documents are based on Drafts.

Hope it helps,

Vitor

Hi Vieira,

I dont know nothing about documents I get - that the point. But You pushed my thoughts to solution, that is not optimal but works. I will try to create object with the same ObjType and DocEntry as the object from array has. If it fails = this was draft.

bool IsDraft( SAPbobsCOM.Documents oUnknownDocument )
{
    SAPbobsCOM.Documents oTestDocument = Company.GetBusinessObject( oUnknownDocument.DocObjectCode );
    return oTestDocument.GetByKey( oUnknownDocument.DocEntry );
}
vitor_vieira
Explorer
0 Kudos

Hi Prsemyslaw,

By instantiating the object with "Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDrafts)" you are guaranteeing it is a draft. But keep in mind that drafts for all document types are stored under the same table and thus accessible through the same object. That is why DocObjectyCode is returning 13 - because that record is a A/R Invoice draft.

I recommend checking SDK help file, see the sample code for the Document object. See:

- Create Draft Document with Down Payment - Create Order from a Draft Document

Hope this helps,

VV

0 Kudos

Hi Vieira, thx for your post. All You wrote is ok but, only if You are "creator" of document object.
In my case I did not created those objects, they have been exposed by external library.
I have array of SAPbobsCOM.Documents without konowledge how this object was created: like draft and then loaded by GetByKey() or like "normal" document.
Now I need to separated drafts from others documents because business logic depends from this fact.
So thats my queston is how to _check_ if the object SAPbobsCOM.Documents represents draft document or not.