Interfaces Dolibarr toward foreign systems: Difference between revisions

Jump to navigation Jump to search
m
Line 3: Line 3:


= Execute your own code on a Dolibarr event =
= Execute your own code on a Dolibarr event =
{{ToTranslate}}
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 mecanism of business triggers. This mecanism allows you to personalize a workflow to have Dolibarr business events being synchronized into another application for example.
You can also use triggers to modify the behaviour of Dolibarr itself: for example, to create automatically a contract when an invoice is validated.


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 containg all information of Dolibarr user that realizes the business event.
* '''$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) Une fois le code réalisé, il n'y a plus qu'à tester, en provoquant l'évènement déclencheur dans Dolibarr. Attention, l'appel au '''run_trigger''' et encapsuler dans un transaction. Si votre trigger renvoie un code ko, la fonction appelante peut annuler la transaction (ceci dépend de la fonction appelante).
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).
Ajouter des traces dans un fichier dans la fonction '''run_trigger''' afin de vous assurer que le code s'exécute bien. Vous pouvez pour cela si vous le désirer, utiliser la fonction
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("mon texte de trace", LOG_DEBUG);
dol_syslog("my log message", LOG_DEBUG);


= List of known events =
= List of known events =

Navigation menu