vtiger Forum Index vtiger
The Honest Open Source CRM
 

HELP- Reqiured Fields
Click here to go to the original topic

 
       vtiger Forum Index -> Help - 4.x
Previous topic :: Next topic  
Author Message
amalley



Joined: 21 Aug 2007
Posts: 4

Posted: Wed Jun 11, 2008 7:38 pm    Post subject: HELP- Reqiured Fields  

Is there anyway to make values within a field required to complete a record?
IE: Potentials>AMT (required) to save.

It seems out of the box a few fields have this feauture however I would like to add it to others..

Thank you...
Back to top  
kiran



Joined: 14 Sep 2007
Posts: 11

Posted: Thu Jun 12, 2008 12:06 pm    Post subject: Re: HELP- Reqiured Fields  

Hi amelley,

This can definitely be done. We call them, the mandatory fields of vtiger. Let's go in a procedural manner of transforming a field to, so called, mandatory field.


Database changes:

Required information:

'tabid' of the module
'fieldid' of the field
'uitype' of the field
'typeofdata' of the field

Obtaining the required information:

tabid:
Code: mysql> select tabid,name from vtiger_tab;
From the query result, pick the required tabid

fieldid:
Code: mysql> select fieldlabel, fieldid from vtiger_field where tabid = <tabid of the field> ;
From the query result, pick the fieldid you want based on the fieldlabel

uitype:
Code: mysql> select fieldlabel, uitype from vtiger_field where fieldid = <fieldid of the field> ;

typeofdata:
Code: mysql> select fieldlabel, typeofdata from vtiger_field where fieldid = <fieldid of the field> ;

Applying the changes:
Now that we have all information in hand, we can go ahead with database changes. Following are the steps to be followed.

Step1:
Change the uitype of the field. This change is being made to show a red asterisk (*) beside the field in the UI.

Code: mysql> update vtiger_field set uitype = ? where tabid= <tabid> and fieldid = <fieldid> ;
? - The value can be obtained from <vtiger>/Smarty/templates/DisplayFields.tpl as described in the File Changes.

Step 2:
Change the typeofdata of the field. This change is being made to tell vtiger the this field is mandatory.

Code: mysql> update vtiger_field set typeofdata = ? where tabid= <tabid> and fieldid = <fieldid> ;
? - Should be something like 'V~M'

Explanation : There are two sections for a typeofdata value which are separated by a '~'. The first section tells what kind of data the field contains (some possible values for this section are V, I, T, D etc., where V- characters, I – integer, D – date and so on) and the second section tells whether the field is an optional one or mandatory (possible values for this section are O, M).

Example for database changes:
Let us take into consideration, the 'Amount' field in Potentials module. The following should be the procedure.

Code: msql> select tabid, name from vtiger_tab;
The tabid for Potentials module is 2

Code: mysql> select fieldlabel, fieldid from vtiger_field where tabid = 2 ;
The fieldid for 'Amount' field is 105

Code: mysql> select fieldlabel, uitype from vtiger_field where fieldid = 105 ;
The uitype for 'Amount' is 71

Code: mysql> select fieldlabel, typeofdata from vtiger_field where fieldid = 105 ;
The typeofdata for 'Amount' is 'N~O'

Code: mysql> update vtiger_field set uitype = 72 where tabid = 2 and fieldid = 105 ;

Quote: mysql> update vtiger_field set typeofdata = 'N~M' where tabid 2 and fieldid = 105;

Code changes:

Files to be looked into:

Smarty/templates/DsiplayFields.tpl

Settings/EditDefOrgFieldLevelAccess.php
Settings/profilePriveleges.php
Settings/DefaultFieldPermissions.php
Settings/UpdateDefaultFieldLevelAccess.php

Users/SaveProfile.php
Users/UpdateProfileChanges.php

Changes:

DisplayFields.tpl:

This file has UI code for all the uitypes. Search for the old uitype ( 71 in this case for 'Amount' field in Potentials module) and check if there is any other uitype with similar code that has red asterisk (*) before the field label, if there is a uitype then it would be our target uitype and no changes are needed for this file.
In the current case, we have the uitype 72 which has the same code as uitype 71 plus the red asterisk.

Code: {elseif $uitype eq 71 || $uitype eq 72}
         <td width="20%" class="dvtCellLabel" align=right>
            {if $uitype eq 72}
               <font color="red">*</font>
            {/if}
            {$fldlabel}
         </td>

If we do not have such a uitype that has red asterisk then we should define a new uitype (unique) by just copying the code snippet under old uitype and adding a red asterisk.

EditDefOrgFieldLevelAccess.php (only one change):

Search for the function 'getStdOutput()' in this file. There will be a conditional statement ('if' condition) that checks for the uitypes and assigns a red asterisk to that uitype. If our target uitype is not listed in the condition, we to need add it there. In our case 72 is not in the conditions so we add it.

Before:
Code: if($uitype == 2 || $uitype == 3 || $uitype == 6 || $uitype == 22 || $uitype == 73 || $uitype == 24 || $uitype == 81 || $uitype == 50 | ...

After:
Code: if($uitype == 2 || $uitype == 3 || $uitype == 6 || $uitype == 22 || $uitype == 72 || $uitype == 73 || $uitype == 24 || $uitype == 81 || $uitype == 50 | ...

profilePrivileleges.php (three changes):

Same change as in EditDefOrgFieldLevelAccess.php. There will be no function called 'getStdOutput()' in this file. Same change have to be made in three places for each mode.

DefaultFieldPermissions.php (only one change):

Same change as in EditDefOrgFieldLevelAccess.php

Before:
Code: if($adb->query_result($fieldListResult,$i,"visible") == 0 || ($uitype == 111 && $fieldtype[1] == "M")  || ($uitype == 111 && $fieldtype[1] == "M") || ($uitype == 117 && $fieldtype[1] == "M"))

After:
Code: if($adb->query_result($fieldListResult,$i,"visible") == 0 || ($uitype == 111 && $fieldtype[1] == "M")  || ($uitype == 111 && $fieldtype[1] == "M") || ($uitype == 117 && $fieldtype[1] == "M") || ($uitype == 72 && $fieldtype[1] == "M"))


UpdateDefaultFieldLevelAccess.php (only one change):

Same change as in EditDefOrgFieldLevelAccess.php but not in any function.

SaveProfile.php (only one change):

Same change as in UpdateDefaultFieldLevelAccess.php but we need to add fieldname to uitype.

Before:
Code: if($uitype == 2 || $uitype == 3 || $uitype == 6 || $uitype == 22 || $uitype == 73 || $uitype == 24 || $uitype == 81 || $uitype == 50 || $uitype == 23 || $uitype == 16 || $uitype == 53 || $uitype == 255 || $displaytype == 3 || $uitype == 20 || ($displaytype != 3 && $fieldname == "activitytype" && $uitype == 15) ||  ($uitype == 111 && $fieldname == 'eventstatus'))

After:
Code: if($uitype == 2 || $uitype == 3 || $uitype == 6 || $uitype == 22 || $uitype == 73 || $uitype == 24 || $uitype == 81 || $uitype == 50 || $uitype == 23 || $uitype == 16 || $uitype == 53 || $uitype == 255 || $displaytype == 3 || $uitype == 20 || ($displaytype != 3 && $fieldname == "activitytype" && $uitype == 15) ||  ($uitype == 111 && $fieldname == 'eventstatus') ||  ($uitype == 72 && $fieldname == 'amount'))

We can get fieldname using the following query:

Code: mysql> select fieldlabel, fieldname from vtiger_field where tabid = 2 and fieldid = 105 ;

UpdateProfileChanges.php (only one change):

Exactly same change as in SaveProfile.php
Back to top  
kiran



Joined: 14 Sep 2007
Posts: 11

Posted: Thu Jun 12, 2008 12:17 pm    Post subject: Re: HELP- Reqiured Fields  

Hi amalley,

Above is the procedure to transform a field to mandatory field. If you have any doubts or you are stuck anywhere, please do get back to us. We will be happy to help you.
Back to top  
petterford



Joined: 16 Jul 2008
Posts: 3

Posted: Wed Jul 16, 2008 5:55 am    Post subject: Re: HELP- Reqiured Fields  

if mandatory field you need to fill it whatever it takes..
Back to top  
carloz



Joined: 11 Sep 2007
Posts: 437
Location: Brescia, Italy

Posted: Mon Jul 21, 2008 12:53 pm    Post subject: Re: HELP- Reqiured Fields  

Hi Kiran,

thank you for great post.

I made it available, in italian, on the vtiger wiki, here:
http://wiki.vtiger.com/index.php/Come_rendere_un_campo_obbligatorio

ciao
carloz
Back to top  
 
       vtiger Forum Index -> Help - 4.x
Page 1 of 1


Powered by phpBB Search Engine Indexer
Powered by phpBB 2.0.15 © 2001, 2002 phpBB Group