676
edits
PolyglotBot (talk | contribs) m (Import interlang links (links to translated versions of this page in other languages) from Multi Language Manager table.) |
|||
| Line 8: | Line 8: | ||
{{TemplateDocDevEn}} | {{TemplateDocDevEn}} | ||
= Execute your own code on a Dolibarr's action = | =Execute your own code on a Dolibarr's action= | ||
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. | 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. | You can also use triggers to modify the behavior of Dolibarr itself: for example, to create automatically a contract when an invoice is validated. | ||
| Line 15: | Line 15: | ||
1) Copy the trigger file '''htdocs/core/triggers/interface_90_all_Demo.class.php-NORUN''' under the new name: | 1) Copy the trigger file '''htdocs/core/triggers/interface_90_all_Demo.class.php-NORUN''' under the new name: | ||
* '''interface_99_all_''Xxx''.class.php''' | |||
*'''interface_99_all_''Xxx''.class.php''' | |||
or | or | ||
* '''interface_99_mod''MyModule_Xxx''.class.php''' | |||
*'''interface_99_mod''MyModule_Xxx''.class.php''' | |||
where ''Xxx'' is a string of your choice starting with uppercase character, ''99'' is the priority number for the execution of your trigger (1 being the top priority) and ''MyModule'' is the name of a module if you want that trigger is activated only if module MyModyle is activated. If you want the trigger to be always active, use ''all'' instead of modMyModule. | where ''Xxx'' is a string of your choice starting with uppercase character, ''99'' is the priority number for the execution of your trigger (1 being the top priority) and ''MyModule'' is the name of a module if you want that trigger is activated only if module MyModyle is activated. If you want the trigger to be always active, use ''all'' instead of modMyModule. | ||
This new file must be saved inside same directory. | This new file must be saved inside same directory. | ||
| Line 45: | Line 49: | ||
2) Edit the file ''interface_99_modMyModule_Myworkflow.class.php'' to rename class ''InterfaceDemo'' by ''InterfaceMyworkflow'' | 2) Edit the file ''interface_99_modMyModule_Myworkflow.class.php'' to rename class ''InterfaceDemo'' by ''InterfaceMyworkflow'' | ||
Then go on page Home-> | Then go on page Home -> Admin Tools -> About Dolibarr ->Triggers. | ||
Your new trigger file must appears in the list without any error message. This means preceding actions have been done successfully. | Your new trigger file must appears in the list without any error message. This means preceding actions have been done successfully. | ||
| Line 77: | Line 81: | ||
You can also use, inside this function, the following preinitialized variables: | You can also use, inside this function, the following preinitialized variables: | ||
* '''$object''' is the object on which action is done (see next chapter) | |||
* '''$user''' is the object containing all information of Dolibarr user that realizes the business event. | *'''$object''' is the object on which action is done (see next chapter) | ||
* '''$langs''' is the object that contains the user language and translations strings | *'''$user''' is the object containing all information of Dolibarr user that realizes the business event. | ||
* '''$conf''' is the object that contains all the Dolibarr configuration. | *'''$langs''' is the object that contains the user language and translations strings | ||
*'''$conf''' is the object that contains all the Dolibarr configuration. | |||
| Line 87: | Line 92: | ||
dol_syslog("my log message", LOG_DEBUG); | dol_syslog("my log message", LOG_DEBUG); | ||
= List of known triggers actions = | =List of known triggers actions= | ||
List of all events that launch triggers are available in [[Table llx c action trigger]]. This is a quick list of those events, identified by value of variable '''$action''' into trigger code and type of variable '''$object''' for each code. | List of all events that launch triggers are available in [[Table llx c action trigger]]. This is a quick list of those events, identified by value of variable '''$action''' into trigger code and type of variable '''$object''' for each code. | ||
In most cases, trigger action code is a key matching this rules: | In most cases, trigger action code is a key matching this rules: | ||
* Start with module name | |||
* Other information (isolated with character _) | *Start with module name | ||
* Action | *Other information (isolated with character _) | ||
*Action | |||
{{TemplateListOfTriggers}} | {{TemplateListOfTriggers}} | ||
This list may be not complete. | This list may be not complete. | ||
= Manage and create a new trigger's action = | =Manage and create a new trigger's action= | ||
To manage other events on objects than the one defined before, you must edit the Dolibarr code to add the following code inside the business method of the class file of the object: | To manage other events on objects than the one defined before, you must edit the Dolibarr code to add the following code inside the business method of the class file of the object: | ||
| Line 147: | Line 153: | ||
</source> | </source> | ||
= Conclusion = | =Conclusion= | ||
You can in few minutes, add an interface from Dolibarr towards another system (or why not towards Dolibarr itself), with no risk since you don't touch anything to Dolibarr files. You only "added" a new trigger file inside the trigger directory. | You can in few minutes, add an interface from Dolibarr towards another system (or why not towards Dolibarr itself), with no risk since you don't touch anything to Dolibarr files. You only "added" a new trigger file inside the trigger directory. | ||
If this new interface can serve a lot of other users, you can package it into a tgz file (see page [[Module_development#Create_a_package_to_distribute_and_install_your_module]]) and submit it on the download area in section external contributions on official Dolibarr web site. | If this new interface can serve a lot of other users, you can package it into a tgz file (see page [[Module_development#Create_a_package_to_distribute_and_install_your_module]]) and submit it on the download area in section external contributions on official Dolibarr web site. | ||
= See also = | =See also= | ||
* [[Hooks system]] | |||
* [[Interfaces Dolibarr toward foreign systems]] | *[[Hooks system]] | ||
* [[Interfaces from foreign systems toward Dolibarr]] | *[[Interfaces Dolibarr toward foreign systems]] | ||
*[[Interfaces from foreign systems toward Dolibarr]] | |||
edits