You are on page 1of 15

The SP_TransactionNotification Stored Procedure

Lisa Mulchinock Business Card Company: SAP Posted on May. 22, 2009 10:33 AM in SAP Business One

Subscribe Print Permalink Share

The SP_TransactionNotification is the only legal way in SAP Business One to receive notification of data-driven events - in order words to do some validation in SAP Business One and prevent the user from doing an action if the validation condition fails. This stored procedure(SP) is created automatically with each database and a default SP looks like this:

What can i do with the SBO_SP_TransactionNotification stored procedure?


You can add your own code in the section 'ADD YOUR CODE HERE'. Since Version 2007 you can now change the Error Code returned by the transaction notification and prevent the transaction from being committed to the database. The SBO_SP_TransactionNotification must return two values - @error and @error_messages. If what is returned in @error is anything other than zero, the transaction will rollback. There are five parameters in the TransactionNotification: 1. @objecttype - the object type you want to use - this is a string value and represents the object eg Business Partner, Invoice etc.

2. 3. 4.

@transaction_type - this is the action type eg Add, Update, Cancel etc. @num_of_cols_in_key - number of columns/fields in the key of the record. @list_of_key_cols_tab_del - returns a tab delimited list of column/field names that represent the object key. @list_of_cols_val_tab_del - returns a tab delimited list of values required to retrieve the object from B1.

5.

Examples of how it can be used.


Example 1: Prevent a user from adding a Sales Invoice if the field 'Customer Ref. No' is empty/blank.

Example 2: Prevent a Purchase Invoice from being added if it does not have a base document (Purchase Order or Goods Receipt PO)

Example 3: Prevent an Incoming Payment from being added if the amount is greater than 2500 for all users except the manager.

As you can see the structure for all samples remains the same and only the query/logic changes.

What the other SBO Stored Procedures do.


In the 2007 version there are 4 stored procedures: - SBO_SP_PostTransactionSupport and SBO_SP_TransactionSupport (since SAP Business One 2007) - SBO_SP_PostTransactionNotice (since SAP Business One 2007) - SBO_SP_TransactionNotification The stored procedures SBO_SP_TransactionSupport and SBO_SP_PostTransactionSupport are encoded and cannot be edited by the user. They are database notification stored procedures which can be used by SAP support to add diagnostic code so they are of no use for customer's daily work. Since they are of no use it is planned to remove them in SAP Business One Version 8.8. SBO_SP_PostTransactionNotice and SBO_SP_TransactionNotification can by edited by the user to add sql code as part of a notification process. The functionalities of both are the same, the only differences being when they are triggered and the ability to use the @error functionality of SBO_SP_TransactionNotification to rollback transactions. SBO_SP_PostTransactionNotice can only be triggered at the end of an action (transaction committed). It is preferable to use SBO_SP_PostTransactionNotice - although as this occurs after the transaction, the @error rollback functionality can not be used.

Further Documentation
The following documenatation is available on the SDN: o Using the SBO_SP_TransactionNotification Stored Procedure: https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uu id/e991e2b9-0901-0010-0395-ef5268b00aaf o SAP Business One Add-On Solution Certification https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/libra ry/uuid/81a22ee1-0701-0010-45aa-ec852e882de3 In two weeks time, our blog will cover the topic of UI folders/tabs and how to create a new folder/tab in your form. So catch you then :-)

Lisa Mulchinock is a senior SDK support consultant for SAP Business One.
If anything in unclear or if you have additional questions regarding this topic of the SP_TransactionNotification please feel free to add a comment here. Comment on this weblog

Showing messages 1 through 42 of 42.

Titles Only Main Topics Transfers 2010-11-30 14:32:00 barry gleeson Business Card [Reply]

Oldest First

Hi is it possible to update a udf on the oitw table with the value from a udf on a transfer. Ie udf on oitw called bin, udf on marketing docs called bin. When transfer takes place the bin udf on the oitw table from the bin udf on the transfer rows where oitw.whscode is = to the target warehouse on the transfer . Is this possible using sp notification.

Transfers 2011-01-19 20:01:55 Lisa Mulchinock Hi Barry,

Business Card [Reply]

It should be possible to check that via the SP_TransactionNotification since you would hold the values in variables and then compare them. However just be aware that direct updates via SQL on System tables are not supported by SAP. Cheers, Lisa

SP_TRANS error logging 2010-10-13 12:53:01 Christian Boos Business Card [Reply] Is there a way to log the fact that the SP_TRANSACTION_NOTIFICATION procedure has prevented someone from doing something, i.e. the error was displayed? I tried inserting information to a user defined table withing the procedure but the data was not inserted. I expect it was because of a rollback somewhere in the process.

SP_TRANS error logging 2010-10-14 05:02:43 Christian Boos Business Card [Reply] It appears that I cannot do an insert along with the select for the error message. If I comment out the select for the error message, the insert works. For example, if the following code is executed, the error message gets displayed but the insert does not work. But if I comment out the Select statement, the insert works.

If the condition exists . . . BEGIN BEGIN INSERT INTO ERROR_LOG_CDB values (2,'yyy') SELECT @Error = 3, @error_message = 'FUTURE DATED CANNOT BE RELEASED TO WHSE CONTACT LOGISTICS' END END I have other logic where I do additional selects along with the one that populates the error message and that all works. I also have this problem when trying to perform and UPDATE. It appears this is only an issue when "modifying" my table in some fashion. I have also reversed the order of the actions, doing the insert after the select.

No difference.

SP_TRANS error logging 2010-10-13 21:12:34 Lisa Mulchinock Hi Christian,

Business Card [Reply]

yes this should be possible - you can write to a log file or a user defined table as you tried to do. Perhaps you just put this after the procedure had finished but i see no reason why it should not succeed. Cheers, Lisa

SP_TRANS Warning Message 2010-10-13 12:50:52 Christian Boos Business Card [Reply] Is there anyway to use the SP_TRANSACTION_NOTIFICATION to issue an error that serves as a warning or allows the user to accept rather than stopping them from continuing?

SP_TRANS Warning Message 2010-10-13 21:10:44 Lisa Mulchinock Hi Christian,

Business Card [Reply]

No there is no way to prevent the rollback if you use the SP_Trans_Not. Cheers, Lisa

Updating a user table at a certain interval 2010-09-28 04:14:57 Rupa Sarkar Business Card [Reply] Hi Experts, What will be the code for writing a stored procedure so that a user table gets updated at a certain date of every month. Regards, Rupa Sarkar

Updating a user table at a certain interval 2010-09-30 23:07:27 Lisa Mulchinock Business Card [Reply] Hi Rupa,

This would not be possible via the SP_TransactionNotification stored procedure since this only reacts to data driven events. You may have to look at another method like Scheduling a batch job etc. Cheers,

Lisa

The SP_TransactionNotification Stored Procedure 2010-09-17 03:28:52 Andrzej Kus Business Card [Reply] Is SAP provides for the introduction of the object on the table ORTT supported by the SP_TransactionNotification Stored Procedure

The SP_TransactionNotification Stored Procedure 2010-09-19 21:09:41 Lisa Mulchinock Business Card [Reply] Hi Andrzej,

This object type is not yet exposed so i would suggest you post your requirement on the DRQ forum http://forums.sdn.sap.com/forum.jspa?forumID=265 Cheers, Lisa

Update PO DocTotal 2010-05-18 06:09:19 Wendy Tranter Business Card [Reply] The Approval procedure doesnt include update of PO Doc Total which is a real deficiency in B1. It's because if you set an approval of any PO over $10,000 needs to be approved. The user can simply create a PO of $10 and then update to $10K and it wont go through the approval procedure. I would like to SP to stop user from updating the PO DocTotal by using the the instance stored in ADOC. Do you think it's possible?? Do you have any suggestion of codes ???

Update PO DocTotal 2010-05-20 20:34:45 Lisa Mulchinock Hi Wendy,

Business Card [Reply]

Yes you can use the SP_TransactionNotification to do this. In the example below i have prevented a user updating any PO whose doctotal is greater than 0. IF @object_type = '22' and @transaction_type = 'U' Begin IF (SELECT doctotal from OPOR WHERE OPOR.DocEntry = @list_of_cols_val_tab_del) > 0 Begin Set @error = -5015 Set @error_message = N'DocTotal cannot be changed' END END

Cheers, Lisa

Update PO DocTotal 2010-05-20 21:00:10 Wendy Tranter Business Card [Reply] Hi Lisa

Thank you very much for replying. Unfortunately though my customer is a little fussy and he would like user to be able to update other details such as delivery date or address, so I wont be able to use your suggestion. In the end, one of the other consultants has helped me with the codes using the DocTotal stored in ADOC for comparison. As a feedback, I think SAP should do something about this business logic deficiency. It really defeat the purpose of approval if user can get around it so easily. Lisa, I really appreciate your time in writing me the code and replying. This blog has been very helpful, thank you very much for writing it. Kind Rgds Wendy

Using this SP to manage field level update access 2009-12-09 13:08:07 Donald Frantum Business Card [Reply] Would it be possible to use this SP to prevent users from changing existing field level entries? What comes to mind is Business Partner Master Data information. I would like a user to be able to add contact information, but not change the the BP Name. If they do, I want an them to receive an error upon UPDATE. Do you think it is possible within this SP and if so, what might be your approach?

Using this SP to manage field level update access 2009-12-09 13:26:30 Donald Frantum Business Card [Reply] I recognize that this SP won't work for master data, as it is transaction based. Is there another SP that would work for this application?

Thanks again, Donald

Using this SP to manage field level update access 2009-12-09 14:51:20 Donald Frantum Business Card [Reply] I missed that, thanks again. How might I go about verifying the current data is not being changed, as in my example?

Donald

Using this SP to manage field level update access 2009-12-09 15:33:29 Donald Frantum Business Card [Reply] I tried this, but it didn't work...perhaps someone can shed some light on how I could change it to work. [code] -- Prohibit anyone but accounting to add Business Partners IF @object_type = 2 AND @transaction_type = 'A'

BEGIN IF EXISTS(SELECT T0.CardCode FROM OCRD T0 WHERE T0.UserSign NOT IN (4,84) AND T0.DocEntry = @list_of_cols_val_tab_del) BEGIN SELECT @error = 0, @error_message = N'You do not have permission to add Business Partners. Please see Accounting.' END END [/code]

Thanks again, Donald

Using this SP to manage field level update access 2009-12-09 17:07:52 Lisa Mulchinock Business Card [Reply] Hi Donald,

As you saw from Daniel's reply its not just transaction data this sp applies to. In your sample there are a couple of issues. - First the object type must be enclosed e.g. '2' - The query has also changed. We're selecing UserSign and not CardCode. I've replaced DocEntry wtih CardCode since DocEntry only applies to docuemnts. Below is the corrected sp for the scenario of preventing users from adding Business Partners: IF @object_type = '2' AND @transaction_type = 'A' BEGIN IF EXISTS (SELECT T0.UserSign FROM OCRD T0 WHERE T0.UserSign NOT IN (4,84) and T0.CardCode = @list_of_cols_val_tab_del) BEGIN SELECT @error = -500, @error_message = N'You do not have permission to add Business Partners. Please see Accounting.' END END If you just want to prevent certain users from adding a BP then you could do this a little easier via Authorisations in Business One. Cheers, Lisa

Using this SP to manage field level update access 2009-12-09 17:19:00 Donald Frantum Business Card [Reply] Thanks Lisa. I know about the Authorization, but I am playing with this and I wanted to give an easy example with which to experiment. Thank you so much for the feedback. BTW, can this be adapted to @transaction_type IN ('D','U') as well or does it have to be modified. If so, how does it recognize the current user vs. the usersign in OCRD?

Using this SP to manage field level update access 2009-12-21 14:34:46 Lisa Mulchinock Business Card [Reply] Hi Donald,

Yes it can be modified for all action types: [A]dd, [U]pdate, [D]elete, [C]ancel, C[L]ose. I would recommend you search the SDK forum for your answers as it contains quite alot of these type of questions. You can also post these type of questions on the SDK forum http://forums.sdn.sap.com/forum.jspa?forumID=56&start=0 Cheers, Lisa

Using this SP to manage field level update access 2010-02-01 00:21:00 shiva shanker Business Card [Reply] Hi Lisa,

this very very informative. i have wrote some logic in the stored procedure SP_TransactionNotification. the logic is for object type 30 (JE). my logic is working properly when JE is posting. The problem while a particular JE (i mean already created JE) is posting reversal the stored procedure logic is not working. could you please explain me why this is happening. i mean when reversal is posting (alternatively it is creating new JE right) so my logic also should work for this Reversal JE. hope you will provide the answer as early as possible. thanks in advance. Regards shiva shanker

Using this SP to manage field level update access 2010-02-07 21:40:22 Lisa Mulchinock Business Card [Reply] Hi Shiva,

I tested this and i think the Reversal works in a different way to the regular JE. From what i observed the reversal is done in the backround so the data add event is not triggered like it is with the regular je. Cheers, Lisa

transaction triggering 2009-11-21 09:37:03 Antonio Burgos Business Card [Reply] You mention in your blog that the Transaction Notification is triggered at the beginning, middle or end of an action. How can i identify these three states?

transaction triggering 2009-12-09 17:50:44 Lisa Mulchinock Hi Antonio,

Business Card [Reply]

I think my wording here may be a bit misleading so i have removed this part to prevent further confusion. As mentioned in the blog the PostTransactionNotice can only be triggered at the end of an action i.e. once it has been committed to the database. With the TransactionNotification store procedure you have much more control as you have the ability to use @error functionality to prevent the object being committed to the database. I hope that helps. Cheers, Lisa

Can I use Trans. Notification for Master Data? 2009-10-09 09:26:06 Daniel Rivas Business Card [Reply] At the time to add a new BP or Item, can I use SP_TN to validate the adding? Is it possible what are the object types for BP data master ?

Thanks.

Can I use Trans. Notification for Master Data? 2009-10-11 19:20:18 Lisa Mulchinock Business Card [Reply] Hello Daniel,

Yes the TransactionNotification stored procedure can be used for any object including master data. The object code for Items is 4 and for Business Partner is 2. Cheers, Lisa

Can I use Trans. Notification for Master Data? 2009-12-09 13:58:03 Daniel Rivas Business Card [Reply] Hello Lisa,

I tested and everything is ok.

Thanks a lot.

What's the difference between the there of them H 2009-06-30 01:47:53 xiao qin liang Business Card [Reply] Hello Lisa: I found that there were three new procedures in B1 2007B version.Except the procedure called SP_TransactionNotification you mentioned on this topic, the rest are: 1)SBO_SP_SBO_SP_PostTransactionNotice 2)SBO_SP_PostTransactionSupport 3)SBO_SP_TransactionSupport

Could you please tell me something about them ?such as: 1 What's the difference between SP_TransactionNotification and the rest ? 2What's the usage of the three procedures ? 3How do they work ? If any samples ? Many thanks in advance

What's the difference between the there of them H 2009-06-30 17:49:16 Lisa Mulchinock Business Card [Reply] Hello Xiao,

As you said in the 2007 version there are 4 stored procedures. - SBO_SP_PostTransactionSupport and SBO_SP_TransactionSupport (since SAP Business One 2007) - SBO_SP_PostTransactionNotice (since SAP Business One 2007) - SBO_SP_TransactionNotification The stored procedures SBO_SP_TransactionSupport and SBO_SP_PostTransactionSupport are encoded and cannot be edited by the user. They are database notification stored procedures which can be used by SAP support to add diagnostic code so they are of no use for customer's daily work. Since they are of no use it is planned to remove them in SAP Business One Version 8.8. SBO_SP_PostTransactionNotice and SBO_SP_TransactionNotification can by edited by the user to add sql code as part of a notification process. As you saw in the blog, the purpose of the Transaction Notifications are to enable the partner/customer to receive notification on any transaction taking place within SAP Business One database. The functionalities of both SBO_SP_PostTransactionNotice and SBO_SP_TransactionNotification are the same, the only differences being when they are triggered and the ability to use the '@error' functionality of SBO_SP_TransactionNotification to rollback transactions. SBO_SP_PostTransactionNotice can only be triggered at the end of an action (transaction committed), whereas SBO_SP_TransactionNotification can be triggered at the beginning, middle or end of an action. It is preferable to use SBO_SP_PostTransactionNotice - although as this occurs after the transaction, the '@error' rollback functionality can not be used. I hope that provides you the info you need about them. I will also add this text to the main blog.

Cheers, Lisa

About this sp_ Prevent a Purchase Invoice from being added if it does not have a base document (Purchase Order or Goods Receipt PO) 2009-06-18 07:53:20 Humberto Pantoja Business Card [Reply] Hi,

can this example works if i have triggered an authorization in the Invoice? because if i have an some kind of autorization this trigger first and only when this was autorized the execute the validation of store procedure. exist some way of avoid this? i want use autorization and this validation of Sp in the same time. thanks

About this sp_ Prevent a Purchase Invoice from being added if it does not have a base document (Purchase Order or Goods Receipt PO) 2009-06-23 17:50:09 Lisa Mulchinock Business Card [Reply] Hello Humberto,

Do you mean you first do an authorization or you mean you first do an Approval? Can you provide more information on your Business Process to help me understand the issue in more detail. Thanks, Lisa

About this sp_ Prevent a Purchase Invoice from being added if it does not have a base document (Purchase Order or Goods Receipt PO) 2009-06-24 08:06:59 Humberto Pantoja Business Card [Reply] sure Lisa thanks,

I had already created a approval process for purchase invoice and this process is triggered for anytime someone try to create an purchase invoice. So plus this i want to add validation using this SP_prevent, but the problem is the validation is executed after the execution of approval procedure and in this company this procedure can delay about one or two days so after two days when the invoice is approved then is executed the SP and block the invoice because this invoice does not have a base document like and purchase order. i hope u understand now. thanks for your help

About this sp_ Prevent a Purchase Invoice from being added if it does not have a base document (Purchase Order or Goods Receipt PO) 2009-06-30 20:58:38 Lisa Mulchinock Business Card [Reply]

Hello Humberto,

the approval process in Business One will always overwrite whatever is in the SP_TransactionNotification stored procedure. However you do have some options to overcome this: 1. As Istvn suggested below do the SP_TransactionNotification validation for the draft document 2. Put the validation that is done in the approval procedure in the SP_TransactionNotification stored procedure also (this may not suit your Business Process) 3. Create a small UI addon that will do the validation before the autorisation screen opens. I tested this issue but the validation does not seem to activate. If i solve it i will post the code. Cheers, Lisa

About this sp_ Prevent a Purchase Invoice from being added if it does not have a base document (Purchase Order or Goods Receipt PO) 2009-06-30 07:37:54 Istvn Kors Business Card [Reply] Hello Humberto

When an approval procedure is activated, the transaction is stored as a draft in the ODRF table. And the object type passed to the procedure is 112 ! So you should write different code to manage the draft documents. For example for a PO you should start your code with something like this: IF @transaction_type = 'A' AND @object_type = '112' And (Select ObjType From ODRF Where DocEntry = @list_of_cols_val_tab_del)='22' -- for PO. Regards Istvn Krs

SP_Trans for Outgoing Payment 2009-06-18 03:00:50 Chi Wa Ken Chan Business Card [Reply] The following code in the SP_Trans can be triggered only when the Outgoing Payment is updated, but cannot for the add.

IF (@object_type = '46') And @transaction_type In ( 'A', 'U' ) BEGIN insert into tempKen values (@list_of_cols_val_tab_del) EXEC CPS_SP_IM_UpdateOPComChkNo @list_of_cols_val_tab_del END

SP_Trans for Outgoing Payment

2009-06-18 16:35:54 Lisa Mulchinock Hello,

Business Card [Reply]

I have tested your TransactionNotification code on 2007A PL49 using this simplified example: IF @object_type = '46' And @transaction_type In ('A', 'U') BEGIN set @error = 4001 set @error_message = 'Stop Outgoing Payment' END And in my testing the error is thrown both during the Add and Update of the Incoming Payment so it seems to be working as expected. Thanks, Lisa

SP_Trans for Outgoing Payment 2009-06-18 18:09:42 Chi Wa Ken Chan Business Card [Reply] thx Lisa,

I found that when adding the outgoing payment, the object_type is 30, it is the type of JE. There is Patch 10 in my B1 environment, is it related? Ken

SP_Trans for Outgoing Payment 2009-06-18 21:17:12 Lisa Mulchinock Hi Ken,

Business Card [Reply]

This should not occur so in this case it may be a bug. Can you check in the latest version to see if it still occurs. If it does it would be best to log a message for support to investigate. Thanks, Lisa

SP_Trans for Outgoing Payment 2009-06-19 04:48:44 Chi Wa Ken Chan Business Card [Reply] Hi Lisa,

there is patch# 10 in our company... I will use the other way to perform the job.

Ken

Questions 2009-05-26 06:20:33 Andrew Tribe Business Card [Reply] Very informative but could you please clarify

1 Are there any restriction regarding the @error value? (You have used values of the form -500x; is this mandated, suggested or merely a coincidence?) 2 Is there a maximum length to the @error_message string, and if so what? Many thanks in advance.

Questions 2009-05-26 17:34:56 Lisa Mulchinock Hi Andrew,

Business Card [Reply]

Thank you for your positive feedback and your questions. 1. Are there any restriction regarding the @error value? Answer: For an easy example i used the error code series -500x. You can see in the blank stored procedure @error is defined as an int (declare @error int). So the only rule is this value must be an integer. 2 Is there a maximum length to the @error_message string, and if so what? Answer: You can see in the blank stored procedure the length of the @error_message is defined when we declare it (declare @error_message nvarchar (200) ) so in this case we have defined that the error string returned is a maximum of 200 characters. You can vary this length just ensure you test it to prevent it bring truncated in the status bar of Business One. The max for the status bar in Business One is about 250 characters. I hope this answers your questions, Cheers, Lisa

Showing messages 1 through 42 of 42.

You might also like