Skip to Content
1

How to run a custom c# script / action when a User Field value is updated?

Oct 31, 2017 at 07:51 PM

60

avatar image

I am looking for a way to automatically run some code when a user field is updated. Basically, I want to insert current Order details into another database and send an email/sms when a user field called U_Approved is changed from 0 to 1. Any idea how to make that in dotNet c# without the use of SQL listeners?

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Johan Hakkesteegt Nov 01, 2017 at 12:51 PM
0

Hi Waseem,

I recommend a console application, that you run in a scheduled task on the server. You could use the following steps:

  1. In the other database, create a table with the field DocNum, and a time stamp
  2. With a simple query get the approved orders' DocNums, that are not already in the table on the other database, and insert them into the table.
  3. Check the orders that were already in the table, against B1 to see if the approval was revoked.
  4. Copy newly approved orders' data from B1 to the other database, and update the time stamp in the DocNum table (see step two).
  5. Remove orders' data for which the approval was revoked (see step three).

If the other database is not a SAP Business One database, you do not even need the DI API.

Regards,

Johan

Show 4 Share
10 |10000 characters needed characters left characters exceeded

You're suggestion is plausible and is based on periodic pull base. This is the most reliable way to do it and prevents any losses in between. SQL dependency is another alternative and there seem to be also built in listeners in SAP as outlined here SAP Business One DI Event Service.

1

Hi Waseem,

The thing with this type of SAP technology is that it is not usually terribly stable, and that you are bound to spend a lot of time getting it to work the first time, and every time you upgrade the system. Next you'll spend a lot of time on trouble shooting after any and every little hickup in your network, DNS, DHCP, firewall, etc, and finally to get it to bend to your specific requirements. And all over again, when you get new server hardware.

Another argument (don't tell SAP I said this), is that if you ever decide to migrate to another ERP system, my solution only requires you to make a few minor changes to a query, whereas you would have to uninstall the SAP event service, and implement (or pay for) an entirely new solution.

Regards,

Johan

1

It is quite interesting that even built in features of SAP B1 itself are built to use a periodic pull solutions and not event listeners: example SAP mailer which sends emails at pre- defined intervals (e.g. 30 seconds), not instantly.

1

Good observation. It may have something to do with the fact that B1 is very much a database driven application.

When you add a document, the client really only runs one or more stored procedures. Also SAP generally advises against adding triggers to the database.

Implementing an event listener on one machine to listen to events on possibly another machine, and then on a third party database software, may be a challenge.

1