31,029
edits
| Line 3: | Line 3: | ||
= Execute your own code on a Dolibarr event = | = Execute your own code on a Dolibarr event = | ||
To execute personalized code after a Dolibarr event (create/modify/remove a third party/invoice/product or other), Dolibarr offers a mechanism of business triggers. This mechanism allows you to personalize a work-flow to have Dolibarr business events being synchronized into another application for example. | |||
You can also use triggers to modify the behavior of Dolibarr itself: for example, to create automatically a contract when an invoice is validated. | |||
To execute personalized code after a Dolibarr event (create/modify/remove a third party/invoice/product or other), Dolibarr offers a | |||
You can also use triggers to modify the | |||
So, to add your own code that will be triggered by a Dolibarr trigger, this is the way to process: | So, to add your own code that will be triggered by a Dolibarr trigger, this is the way to process: | ||
| Line 62: | Line 60: | ||
You can also use in this function the preinitialized following variables: | You can also use in this function the preinitialized following variables: | ||
* '''$object''' is the object on which action is done (see next chapter) | * '''$object''' is the object on which action is done (see next chapter) | ||
* '''$user''' is the object | * '''$user''' is the object containing all information of Dolibarr user that realizes the business event. | ||
* '''$langs''' is the object that contains the user language and translations strings | * '''$langs''' is the object that contains the user language and translations strings | ||
* '''$conf''' is the object that contains all the Dolibarr configuration. | * '''$conf''' is the object that contains all the Dolibarr configuration. | ||
4) | 4) Once your trigger file has been developed, last action is to test by using Dolibarr to execute the business event that should trigger your code. Warning, call of function '''run_trigger''' is encapsulated into a transaction. If your code return a KO code, the calling function may rollback the transaction (this depends on calling function). | ||
Add log information inside your function '''run_trigger''' to know if your code is correctly triggered and runs correctly. For this, you can use the function | |||
dol_syslog(" | dol_syslog("my log message", LOG_DEBUG); | ||
= List of known events = | = List of known events = | ||