cancel
Showing results for 
Search instead for 
Did you mean: 

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

former_member530696
Participant

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?

Accepted Solutions (1)

Accepted Solutions (1)

Johan_H
Active Contributor
0 Kudos

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

former_member530696
Participant

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.

Johan_H
Active Contributor

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

former_member530696
Participant

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.

Johan_H
Active Contributor

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.

Answers (0)