cancel
Showing results for 
Search instead for 
Did you mean: 

Get last Payment Draft DocEntry added by user

0 Kudos

Hi all. I have a problem with Payment Draft Document.

We set an approval procedure to Outgoing Payment. So when a user add Outgoing Payment Document it firstly add Payment Draft Document.

So in the Form Data Event I wrote that

if EventType==Add and BeforeAction==False Then

string objectCode=oCompany.GetNewObjectKey();

string objectType=oCompany.GetNewObjectType();

But these two methods always return an empty string. I noticed that if I will add document by code (calling Add() method) then after calling these above two methods does not return an empty string.

The problem is that these methods don't work when user adds document normally.

I don't think that writing query is a good idea. Like SELECT MAX(DocEntry) FROM OPDF.

Because you cannot be sure that DocEntry always increases by adding +1 unit.

For example we have A/P Invoice document with DocEntry 1, 2 ,6, -8, -10 and etc.

So what is the best way to get DocEntry when user add?

1.With help of SBO_SP_TransactionNotification(calling method in it)

OR

2. With help of DI Event Service.

P.S. I never used none of them.

Please, help me to resolve my problem.

Thanks in advance.

Regards, Kamil.

Accepted Solutions (1)

Accepted Solutions (1)

pedro_magueija
Active Contributor
0 Kudos

Hi Kamil,

The key is included in the event arguments. The BusinessObjectInfo.ObjectKey contains the xml representation of the key of the created document.


Pedro Magueija


LinkedIn Logo View Pedro Magueija's profile on LinkedIn
Follow @pedromagueija on Twitter

If this answer was helpful or correct consider marking it as such.

Answers (3)

Answers (3)

0 Kudos

I can't find any solution

pedro_magueija
Active Contributor
0 Kudos

Hi Kamil,

In that case, can you not query the draft table (include a filter to take only drafts of your document type and order them desc)?

E.g.: SELECT TOP 1 DocEntry FROM ODRF WHERE ObjType = '<the_type>' ORDER BY DocEntry DESC


Pedro Magueija


LinkedIn Logo View Pedro Magueija's profile on LinkedIn
Follow @pedromagueija on Twitter

If this answer was helpful or correct consider marking it as such.

0 Kudos

Hi Pedro,

But how can I be sure that DocEntry will not be negative value?

if there is negative value which I need then this query will return another result

For example, in A/P Invoice there is negative DocEntry (like -9, -10 etc.)

pedro_magueija
Active Contributor
0 Kudos

Hi Kamil,

In the ODRF there are no negative DocEntry entries that I can see. Where are you finding your negative DocEntry? Is it on the ODRF table?


Pedro Magueija


LinkedIn Logo View Pedro Magueija's profile on LinkedIn
Follow @pedromagueija on Twitter

If this answer was helpful or correct consider marking it as such.

0 Kudos

I don't need ODRF, Not oDrafts. Just forget about this)

I am working with OPDF, oPaymentsDraft.

For your question, there is not negative DocEntry values in OPDF table.

But FOR EXAMPLE in OVPM (Outgoing Payment) table there are negative DocEntry values.

So, I think that in OPDF table there also will be negative DocEntry values in future.

You never be sure that DocEntry in the OPDF will not negative.

P.S. In above I wrote A/P Invoice insted of Outgoing Payment

pedro_magueija
Active Contributor
0 Kudos

Hi Kamil,

I've just created a couple of outgoing payments (with an approval) and I still don't get negative DocEntry.

Checked both tables OPDF and OVPM.

Are you doing something else during the creation of the Payment that I'm missing?


Pedro Magueija


LinkedIn Logo View Pedro Magueija's profile on LinkedIn
Follow @pedromagueija on Twitter

If this answer was helpful or correct consider marking it as such.

0 Kudos

I also created Outgoing Payments (with or without approval) and I have negative DocEntry.

And here, for example DocEntry -20 and 20 are absolutely different documents.

I don't know how it was happend   And in which situation.

P.S. Internal Number is DocEntry

pedro_magueija
Active Contributor
0 Kudos

Hi Kamil,

I'm afraid I've never seen this kind of situation, and I can't offer any insight.

In this case I'd try to figure out if this is a normal behavior in B1 by opening a ticket with SAP.

Please let us know if you do find a solution or get a reply from SAP.


Pedro Magueija


LinkedIn Logo View Pedro Magueija's profile on LinkedIn
Follow @pedromagueija on Twitter

If this answer was helpful or correct consider marking it as such.

0 Kudos

Hi Pedro,

I have problem with draft document now.

So when I add Outgoing Payment document, SAP B1 add draft document. So with SDK I cannot catch if draft document added or when added, or which draft document added.

I used Event Logger but it also cannot catch.

I can only catch DataAddBefore (before action is true) Event for Outgoing Payment document, and it was trigger TWO TIMES. But it does not give me any useful information. Because approval procedure enabled for this document.

Regards, Kamil

0 Kudos

Hi again. Thank you for your replies.

But it works when Outgoing Payment adds without approve.

Firstly I need draft DocEntry.

When I activate Approval template for Outgoing Payment and when user adds, SAP B1 adds draft for payment. So BusinessObjectInfo.ObjectKey is null.

In DataEvent I wrote if BusinessObjectInfo.FormTypeEx == "426" (it is Outgoing Payment form)

What is wrong?

Regards, Kamil

pedro_magueija
Active Contributor
0 Kudos

Hi Kamil,

Please post the entire code, otherwise it is very hard to know what might be the issue.

Also note that, even when saving a draft the BusinessObjectInfo still contains the key for the draft.

The object type of the BusinessObjectInfo will be 112 (Draft).


Pedro Magueija


LinkedIn Logo View Pedro Magueija's profile on LinkedIn
Follow @pedromagueija on Twitter

If this answer was helpful or correct consider marking it as such.

0 Kudos

As I mentioned above, I just wrote this:

if (BusinessObjectInfo.FormTypeEx == "426" && BusinessObjectInfo.EvenType==SAPbouiCOM.BoEventTypes.et_FORM_DATA_ADD)

{

string objectKey=BusinessObjectInfo.ObjectKey;

}


So objectKey is always empty when Approval Template activated for Outgoing Payment.

Otherwise it is not null.


I don't need oDrafts (which type is 112, table is ODRF),

I need oPaymentsDrafts (type is 140, Table is OPDF)

former_member233854
Active Contributor
0 Kudos

In fact I have tested here and I find a strange behaviour of Outgoing Payment, the beforeAction false doesn't trigger when using a Approval

0 Kudos

Yes, that is true. I also tested.

I thing that the reason is when you want to add Outgoing Payment document, instead of this SAP B1 adds Payment Draft document. So BeforeAction will be false when "real" document added.

former_member233854
Active Contributor
0 Kudos

It is how Pedro said, just adding an example how to get the XML


System.Xml.XmlDocument oXml = new System.Xml.XmlDocument();

oXml.LoadXml(businessObjectInfo.ObjectKey);

int docEntry = int.Parse(oXml.SelectSingleNode("//DocEntry").InnerText);