[Vtigercrm-developers] copy a recordModel?
    Alan Lord 
    alanslists at gmail.com
       
    Thu May  7 08:03:42 GMT 2015
    
    
  
I am writing a custom action for a client which is like a cross between 
duplicate and convertlead.
In my class that is responsible for creating the new record, at the 
moment I am doing something like this:
> 	    // Get the current record details
>     	$recordModel = Vtiger_Record_Model::getInstanceById($recordId, $request->getModule());
>
> 	    // Create the new Contract
> 	    // Map these to a new record
> 	    // Set the new records' values as appropriate
>         $newContract = $this->mapContract($recordModel, $assignId, $newContractName);
In the mapContract function I start by doing:
   $newContract = $recordModel;
because I want to retain quite a lot of the data in the 120 plus fields. 
I then remove the id:
    $newContract->setId('');
Then update the fields I need for the new record.
The trouble is I can't save it. I've tried setting the newContract mode 
to 'createmode" before save but it fails as there is no id...
Am I barking up the wrong tree here? Should I use the server API? Or 
should I start with a getCleanInstance of the Record_Model and populate 
that?
TIA
Al
    
    
More information about the vtigercrm-developers
mailing list