[Vtigercrm-developers] edit field type

lucia digirolamo l.digirolamo at websonica.net
Thu Oct 8 13:59:20 GMT 2015


Thanks,

Unfortunately, change the type didn't work, so I had to create a new 
field with type text, then copy existing data to new field with sql 
query provided by Joe

update vtiger_accountscf set cf_{newfield} = cf_{oldfield}

then delete old field.

Now leading zeros are kept but, oddly, only if I save the record during 
edit mode. So:

If I try to quickly edit the record by simply clicking on the field, the 
leading zero is not kept.

If I modify the record by clicking on the 'edit' button, then adding the 
zero, then click on green 'save' button, then the zero is kept.

Really odd isn't it?

lou



On 08/10/2015 09:28, Alan Lord wrote:
> On 07/10/15 18:57, lucia digirolamo wrote:
>> Hi,
>>
>> A while ago I created a custom field for my Organizations module to hold
>> the vat number. Now I just realized that this custom field does not keep
>> the leading zeros. I don't remember what type I used, probably integer,
>> since vat number contains no letters, but surely is not a text type,
>> because I creating a new text field for testing purpose and if I enter
>> here a number starting with zero, the zero is kept. But I cannot simply
>> delete the existing field and substitute it with a new text field
>> because if I do I would lose all the data that have been already
>> inserted. So I have to change the type of this custom field from
>> whatever it is now (that doesn't keep zeros) to a text field (which
>> keeps zeros).
>
> You can do the following (work on a backup system first if you are 
> unsure what your doing)
>
> Change the UIType in vtiger field...
>
> If your field is called cf_123 then edit the row in vtiger_field where 
> the fieldname = cf_123 and change the UIType from 7 (or whatever it 
> is) to 1.
>
> You might also need to review the information in the typeofdata column 
> too. You probably want something like N~O (or even maybe I~O). Try 
> making some changes and see how it affects your ability to populate 
> the field.
>
> Find the column of the real field in the database. If your field is 
> called cf_123 and it is for the Organization module then in the table 
> vtiger_accountscf will be a column called cf_123.
>
> Look at the structure of that column and see if you need to change it. 
> You can change some types such as from INT or DECIMAL() to VARCHAR() 
> but it might not work the other way around.
>
> You probably want it to be type VARCHAR if it needs to store leading 
> zeros. INT, by definition, cannot.
>
>
> HTH
>
> Al
>
>
> _______________________________________________
> http://www.vtiger.com/
>



More information about the vtigercrm-developers mailing list