[Vtigercrm-developers] Initialize fields when I created a new record

enrico manna enrico.manna at web2e.it
Fri Oct 27 14:28:42 GMT 2017


ok, I solved it ...
It's correct also for related fields use this code:

        $fieldName = "accountid";
        $recordModel->setData($fieldName, '1');

in this case the value of display is set.



2017-10-27 13:25 GMT+02:00 enrico manna <enrico.manna at web2e.it>:

> Hi all,
>
> When I created a new record in my custom module  I can initialize the
> fields with method: getCleanInstance
>
> In the example bellow I initialized the filed [1]  customnamefield  with a
> default value.
>
> The second field [2], for example account, is composed by id and display
> (select field),
> in this case I don't understand how initialize the display value [2B].
>
> -----------------------------------------------
>     public static function getCleanInstance($moduleName) {
>
>         $focus = CRMEntity::getInstance($moduleName);
>         $modelClassName = Vtiger_Loader::getComponentClassName('Model',
> 'Record', $moduleName);
>         $instance = new $modelClassName();
>         $recordModel =  $instance->setData($focus->
> column_fields)->setModule($moduleName)->setEntity($focus);
>
>         // [1] Normal text input
>         $fieldName = "customnamefield";
>         $recordModel->set($fieldName, 'this is default value');
>
>
>         //[2A] related field
>         $fieldName = "accountid";
>         $recordModel->setData($fieldName, '1');
>
>          //[2B] related field display value  - WRONG
>         $fieldName = "accountid_display";
>         $recordModel->setData($fieldName, 'Account name');
>
>
>         return $recordModel;
>
>     }
>
> Can  someone help me how I can initialize different type of filelds ?
> --
>
> *Enrico Manna*
> *Web2e - Strategie per il web*
>
> Web: http://www.web2e.it
>
>
>
>


-- 

*Enrico Manna*
*Web2e - Strategie per il web*

Tel: 02 3654 3268
Cell: 340 9325624
Email: enrico.manna at web2e.it
Skype: webem_enrico
Web: http://www.web2e.it
Linkedin: it.linkedin.com/in/enricomanna/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20171027/71b25929/attachment-0001.html>


More information about the vtigercrm-developers mailing list