This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
en:devel:saverecordfromwithin [2015/03/02 16:52] joebordes [Example of DataTransform transformation] |
en:devel:saverecordfromwithin [2019/08/30 12:58] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== How to properly save a record from within the application ====== | ====== How to properly save a record from within the application ====== | ||
+ | |||
+ | <WRAP center round info 60%> | ||
+ | Please [[http://blog.corebos.org/blog/feedingdatatosave|read this very well explained article]] from Luke. | ||
+ | </WRAP> | ||
===== Background ===== | ===== Background ===== | ||
Line 41: | Line 45: | ||
* DataTransform is a class dedicated exclusively to transforming fields. It has high level methods that can transform all fields in a module and individual transformation methods for each field type. | * DataTransform is a class dedicated exclusively to transforming fields. It has high level methods that can transform all fields in a module and individual transformation methods for each field type. | ||
- | ==== Example of DataTransform transformation ==== | + | ===== Example of DataTransform transformation ===== |
The DataTransform was introduced with the Web Service interface where the problem of making sure the information being sent in was consistent and in the correct format. | The DataTransform was introduced with the Web Service interface where the problem of making sure the information being sent in was consistent and in the correct format. | ||
Line 72: | Line 76: | ||
$ticket->column_fields['ticketstatus'] = $newStatus; | $ticket->column_fields['ticketstatus'] = $newStatus; | ||
$ticket->mode = 'edit'; | $ticket->mode = 'edit'; | ||
- | $handler = vtws_getModuleHandlerFromName('Events', $adminUser); | + | $handler = vtws_getModuleHandlerFromName('HelpDesk', $adminUser); |
$meta = $handler->getMeta(); | $meta = $handler->getMeta(); | ||
$ticket->column_fields = DataTransform::sanitizeForInsert($ticket->column_fields,$meta); | $ticket->column_fields = DataTransform::sanitizeForInsert($ticket->column_fields,$meta); | ||
Line 78: | Line 82: | ||
$ticket->save('HelpDesk');</code> | $ticket->save('HelpDesk');</code> | ||
- | ==== Example of manual transformation ==== | + | ===== Example of manual transformation ===== |
In our [[https://github.com/tsolucio/Timecontrol|Timecontrol]] module we have this situation and we resolved it with a manual transformation basically because we didn't know of the existence of the DataTransform class then. | In our [[https://github.com/tsolucio/Timecontrol|Timecontrol]] module we have this situation and we resolved it with a manual transformation basically because we didn't know of the existence of the DataTransform class then. |