[Vtigercrm-developers] Function vtws_revise creates an incorrect history entry

MrJingles paddy at renaissancegroup.co.uk
Tue Jun 7 07:01:13 GMT 2016


Hi Preexo, 

Thanks for the reply. I will try to provide some clarity as I have started
to ask for assistance with two separate issues. Let me focus on my last
point which is in relation to the vtws_revise function, to see if anyone can
help me:

Alan very easily identified the missing code that I needed to get it to
work. I have updated my original code and pasted it below.

My issue is as previously detailed, but I will try to provide a bit more
clarity around this as well (everything detailed below is in a test
environment so does not necessarily reflect what I want to happen in the
live system):

*Scenario 1*
1. I have a Custom Module called Apartments.
2. I have a Workflow configured to run a Custom Function every time an
Apartment is saved.
3. The Custom Function is shown below - it is configured to update the
custom field (cf_852) to a value of 'For Sale'.
4. If I open an apartment that has the custom field in question showing as
Sold, and then Edit and Save the record, the custom function works and the
field gets changed to 'For Sale'.
5. Perfect!! The code works!!

*Scenario 2 - Running the same Custom Function from a different module*
1. I have a Contact that has a related field linked to the apartment in
scenario 1.
2. I have a Workflow configured to run a Custom Function every time a
Contact is saved.
3. The same Custom Function is shown below (with one minor difference being
that the apartmentid is identified by a different field for the contact).
4. If I open the Contact and then Edit and Save it, the Custom Function is
called and fails with the error:
"Permission to perform the operation is denied for id".
5. Therefore, the exact same code does not work when updating a field in a
different module to the one that triggers the custom function.

I have switched on the debug logging and checked the logs and can see that
the Custom Function is called in the exact same way for both scenarios. But
as I mentioned, it fails for scenario 2.

I am wondering why?? I have tried digging through the code and can see
things in the log files, but didn't want to write too much information in a
post here. I am happy to do that if required.

Please let me know if you need any further information and I will provide
it...

Thanks, Paddy

*My Custom Function Code*
<?php

function Testing($entity){

require_once('include/Webservices/Utils.php');
require_once('include/Webservices/Revise.php');
require_once('modules/Users/Users.php');

	global $current_user, $adb, $log;

	$entityarray = get_object_vars($entity);

	$apartmentid = $entity->id;
	$fielddatatoupdate = 'For Sale';

	$log->debug("Entering Custom Workflow Function: Update Field");
	$log->info("Trigerring for Apartment");

	$parameters = array( 
	'cf_852' => 'For Sale',
	'id' => $apartmentid
	);

	$infoparameters = print_r($parameters, true);

	$log->info("Updating field. Info is: ".$infoparameters.".");
	
	global $VTIGER_BULK_SAVE_MODE; 
	$bsval = $VTIGER_BULK_SAVE_MODE; 
	$VTIGER_BULK_SAVE_MODE = true; 

	$toupdate = vtws_revise($parameters, $current_user);

	$VTIGER_BULK_SAVE_MODE = $bsval;
	
	$log->debug("Custom Workflow - Exiting the Update Field Function.");
}

?>



--
View this message in context: http://vtiger-crm.2324883.n4.nabble.com/Function-vtws-revise-creates-an-incorrect-history-entry-tp19167p19174.html
Sent from the vtigercrm-developers mailing list archive at Nabble.com.


More information about the vtigercrm-developers mailing list