CoreBOSBB
AJAX editing leads to empty date fields on aftersave event - Printable Version

+- CoreBOSBB (https://discussions.corebos.org)
+-- Forum: Development (https://discussions.corebos.org/forumdisplay.php?fid=18)
+--- Forum: coreBOS Development (https://discussions.corebos.org/forumdisplay.php?fid=4)
+--- Thread: AJAX editing leads to empty date fields on aftersave event (/showthread.php?tid=753)



AJAX editing leads to empty date fields on aftersave event - Guido1982 - 10-25-2017

I have implemented an aftersave event on SalesOrders. When a salesorder is saved, the related assets are updated to change some values depending on the SalesOrder. Here is the code that does that:

PHP Code:
            if ($soData['sostatus'] == 'Niet geleverd' || $soData['sostatus'] == 'Ingepland') {
                
$r $adb->pquery("SELECT * FROM vtiger_crmentityrel WHERE crmid = ? AND relmodule = ?", array($soId'Assets'));
                if (
$adb->num_rows($r) > 0) {
                    while (
$row $adb->fetch_array($r)) {
                         
// Update the asset "keurstatus"
                        
$ass = new Assets();
                        
$ass->retrieve_entity_info($row['relcrmid'], 'Assets');
                        
$ass->id $row['relcrmid'];
                        
$ass->mode 'edit';
                        
$ass->column_fields['cf_966'] = $new_asset_status// Adjust custom field ID
                        
$handler vtws_getModuleHandlerFromName('Assets'$current_user);
                        
$meta $handler->getMeta();
                        
$ass->column_fields DataTransform::sanitizeRetrieveEntityInfo($ass->column_fields$meta);
                        
$ass->save('Assets');
                    }
                }
            } 

The weird thing is, when I perform the action by doing a full edit on the SalesOrder, it works as expected. But when I do an inline edit on the SalesOrder, all the date fields in the asset (custom and regular) get set to '0000-00-00'. This happens after the last line of code (I output the column fields to a temp file and tested that in various places in the proces). I've never experienced this before. Do I need to set some $_REQUEST value maybe?


RE: AJAX editing leads to empty date fields on aftersave event - joebordes - 10-25-2017

I suppose that if the user you test with has ISO date format (Y-m-d) it works correctly. If that is the case, I'd say you have to unset the ajxaction REQUEST varaible:


PHP Code:
$_REQUEST['ajxaction'] == 'DETAILVIEW' 


when in AJAX inline edit mode this variable is set to indicate that all the values are set to database values. In other words, in inline edit mode the application only expects the field being saved to be in the user format, all the rest have been directly read from the database and do not need conversion. Since you are converting them, when MySQL see the value it is in the format of the user and blanks it. At least that is what I am suspecting.

try and


PHP Code:
unset($_REQUEST['ajxaction']); 



in your handler and let me know how it goes.


RE: AJAX editing leads to empty date fields on aftersave event - Guido1982 - 10-30-2017

Thought it would be something along those lines, thanks! I'll try and keep you posted.


RE: AJAX editing leads to empty date fields on aftersave event - Guido1982 - 04-11-2018

I'm going to work on this issue in the near future, you said:

Quote:Since you are converting them, when MySQL see the value it is in the format of the user and blanks it.

Do you mean by converting:

PHP Code:
$ass->column_fields DataTransform::sanitizeRetrieveEntityInfo($ass->column_fields$meta); 
As in: that call does NOT convert my date field to database format since it does not expect it to be changed, because the REQUEST['ajxaction'] variable is set?

Your solution seems to work (https://github.com/Luke1982/ServiceJob/commit/1a561f053b9cc2f9867e7f58dbb2965eee04e571)! Thanks!