[Vtigercrm-developers] copy a recordModel?
Hamono, Chris (DPC)
Chris.Hamono at sa.gov.au
Fri May 8 03:56:43 GMT 2015
Hi Alan
You probably need to set the 'action' variable.
I do it a bit differently it may help you..
// copy fields, remember to allow for field name differences
// $req and $newreq are Vtiger_Request objects
$newreq = $this->CopyFields($req);
// use setglobal because internally vtiger MAY use $_REQUEST!
$newreq->setGlobal('module', 'contacts');
$newreq->setGlobal('action', 'Save');
$sc = new Vtiger_Save_Action();
// bypass the normal process() call
$contact = $sc->saveRecord($newreq);
The above example is of course for the contacts module
Chris
-----Original Message-----
From: vtigercrm-developers-bounces at lists.vtigercrm.com [mailto:vtigercrm-developers-bounces at lists.vtigercrm.com] On Behalf Of Alan Lord
Sent: Thursday, 7 May 2015 5:34 PM
To: vtigercrm-developers at lists.vtigercrm.com
Subject: [Vtigercrm-developers] copy a recordModel?
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
_______________________________________________
http://www.vtiger.com/
More information about the vtigercrm-developers
mailing list