Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Update a record through vtlib within app
#1
I'm in a situation where I need some code that updates an existing record from within the app. Since the update operation needs to trigger a workflow, I need a vtlib method to update. I've been searching for a bit now but can't find any clear docs on this. I suppose I need to include module.php and call some update method? Does anyone have any pointers to examples or docs?

Hmmm, reading the doc on how to save a record, I see that the intention is to first re-open the entity by getting the instance of it.. Modify where needed and then save it... Is that correct?
Reply
#2
You can do what is said in the wiki, the page you found is more or less correct, but it is much easier to use the webservice interface. Exactly as I recommended with the create:

https://github.com/tsolucio/corebos/blob/master/build/HelperScripts/importcsv.php#L62

you can use vtws_update or vtws_revise to update a record.
update requires ALL fields to be passed in, at least all mandatory fields while revise will only update the fields you give it with no validations.

it is easier than having to retrieve, sanatize and save

let me know how it goes
Joe
TSolucio
Reply
#3
Ok, what I have so far:

PHP Code:
global $adb$current_user;

$query 'SELECT salesorderid FROM vtiger_salesorder WHERE salesorder_no=?';
$params = array('ORD3199');
$result $adb->pquery($query$params);
$so_crm_id $adb->query_result($result0'salesorderid');

$so CRMENtity::getInstance('SalesOrder');
$so->retrieve_entity_info($so_crm_id'SalesOrder');

$so->column_fields['sostatus'] = 'Ingepland';
$so->column_fields['duedate'] = '2016-07-28';
$so->mode 'edit';

$handler vtws_getModuleHandlerFromName('HelpDesk'$current_user);
$meta $handler->getMeta();
$so->column_fields DataTransform::sanitizeForInsert($so->column_fields,$meta);
$so->column_fields DataTransform::sanitizeTextFieldsForInsert($so->column_fields,$meta);

$so->save('SalesOrder'); 

Some variables have been filled out with dummy values, but you get the idea. I now get a fatal error:

Code:
Fatal error: Call to a member function FetchRow() on a non-object in {SERVER_PATH}/public_html/crmdevelop/include/database/PearDatabase.php on line 893

Caused by the save method...

(07-28-2016, 09:46 AM)joebordes Wrote: You can do what is said in the wiki, the page you found is more or less correct, but it is much easier to use the webservice interface. Exactly as I recommended with the create:

https://github.com/tsolucio/corebos/blob/master/build/HelperScripts/importcsv.php#L62

you can use vtws_update or vtws_revise to update a record.
update requires ALL fields to be passed in, at least all mandatory fields while revise will only update the fields you give it with no validations.

it is easier than having to retrieve, sanatize and save

let me know how it goes

Same time-reaction here... When I use the webservice way, how do I identify which record I want to update? Add the crmid to the '$row' array?
Reply
#4
This is because Inventory modules (Q, SO, PO, I) are special due to the product lines. To correctly save these modules from within the application like that you have to do this trick:



PHP Code:
$_REQUEST['action'] = 'SalesOrderAjax'

before the save(), that is basically telling the application to not save the product lines nor do anything with them. That should fix your error.
Joe
TSolucio
Reply
#5
Good to have you around... However, that leads to:

Code:
Sorry! Attempt to access restricted file.
We are looking for this file path: modules//.php
We are looking here:
Real file path:

I'll try to get the webservice way running in the meantime.

Got it. Code is now:

PHP Code:
include_once 'include/Webservices/Revise.php';
include_once 
'modules/Users/Users.php';

global 
$adb;

$query 'SELECT salesorderid FROM vtiger_salesorder WHERE salesorder_no=?';
$params = array('ORD3199');
$result $adb->pquery($query$params);
$so_crm_id $adb->query_result($result0'salesorderid');

$user = new Users();
$current_user $user->retrieveCurrentUserInfoFromFile(Users::getActiveAdminId());

$wsid vtws_getWebserviceEntityId('SalesOrder'$so_crm_id);

$data = array(
        
'id'        => $wsid,
        
'duedate'    => '2016-07-28',
        
'sostatus'    => 'Ingepland'
    
);


$_REQUEST['action'] = 'SalesOrderAjax';
$so vtws_revise($data$current_user); 

Thanks for the tip about the inventory lines, would have never figured this out alone.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)