Results 1 to 7 of 7

Thread: Making a field not 'required'

  1. #1
    Neilltech is offline Member
    Join Date
    Mar 2010
    Posts
    11

    Default Making a field not 'required'

    Hello all,

    I'm quite new to Sugar and would greatly appreciate some help with this. To begin with, I'm using Sugar 5.2 Enterprise.

    When converting a lead, both account name and last name are considered required fields. Both these fields are default out of the box, not custom. As my company
    uses custom fields for the information covered by those, I'm trying to remove their 'required' status.

    I went to /sugar/modules/Leads/metadata/editviewdefs.php and found the following:

    array (
    array('name'=>'last_name',
    'displayParams'=>array('required'=>true),
    ),

    I removed the 'displayParams' line and performed a quick repair and rebuild. The field, tragically, is still required. Is there anywhere else I have to make this change?

    I've had my sight set on ConvertLead.php and ContactFormBase.php, I looked through the code there and these look like likely candidates to resolve this. I'm not a programmer however so I'm reticent to make any changes in these unfamiliar areas. Anyone ever work with these before?

    Thanks again for your help,
    Roberto Ruiz

  2. #2
    eitrix's Avatar
    eitrix is offline Sugar Community Member
    Join Date
    Aug 2010
    Location
    Serbia
    Posts
    396

    Default Re: Making a field not 'required'

    instead of changing modules files, do it in safeway by creating if not exists directory and copy that file here:

    sugar/custom/modules/Leads/metadata/editviewdefs.php

    tried with setting it false?
    CRM Software Engineer
    Eontek - www.eontek.rs

  3. #3
    robertbmirth is offline Sugar Community Member
    Join Date
    Jun 2010
    Location
    Irvine, CA
    Posts
    345

    Default Re: Making a field not 'required'

    The file you modified, 'editviewdefs.php' is part of the View in the Model-View-Controller (MVC) paradigm. You're essentially just changing what the user sees, not the underlying model.

    If you're "not a programmer" then this is probably something that's going to be over your head, as accounts and contacts are some of the more fundamental modules. Don't say I didn't warn you.

    I haven't done this yet (I'm going to say now that its highly risky changing this behavior in sugar) but here are some general guidelines for what you'll have to do:

    You'll have to make modifications to the Contact's Model, View, and possibly Controller to pull this off.

    For the model, you'll need to go through the vardef declarations to find the information you need. For last name, you can find this declaration in include/sugarobjects/templates/person/person. You can find it and switch 'required' to false. One major problem with modifying this field is that its a superclass for not just Contacts, but Leads and Prospects as well (and possibly others) so you'll not only be modifying the status of your contacts but also of your other classes. You could possibly overwrite this vardef declaration in the Contacts vardef declaration but I doubt that would work (I haven't tried it). For the account name, that one is going to be a little more tricky as its a relationship and not just a field. I can't really help you there at this point.

    I'm pretty sure you're good on the view section with the modification you did, however you need to do this in the Contacts module and not the Lead module. Essentially when you convert a lead it prepopulates the new contact form which retrieves its view from editviewdefs.php. I haven't done much with views so I may be wrong.

    The controller is probably the most elusive part of this paradigm, and I honestly wouldn't know if you have to change this at all, but if you do its going to mean a lot of problems for the rest of your system, because the Contacts controller is very simple, which means if any functionality needs to be changed it would most likely be in the SugarController, which is the controller that all other controllers extend.

    At best, directly modifying these things is probably your worst option. You're better off either figuring out how to use these fields rather than your custom ones, or creating entirely new custom modules. If you use module builder, you shouldn't need to know too much coding to work out what you need.
    Robert Beckman
    Software Engineer
    Mirth Corporation

  4. #4
    Neilltech is offline Member
    Join Date
    Mar 2010
    Posts
    11

    Default Re: Making a field not 'required'

    Hello Robert,

    Thanks so much for your advice, I'm definitely going to follow it. If I could trouble you with another question?

    So, right now, I have Sugar setup so that all the different types of information we need can start being collected from the Leads module and it gets carried over automatically to Accounts or Contacts. I couldn't find a way to add an already existing field to a module it didn't belong to (like Account_Name into Leads for example) because if I try to create Account_Name into Leads Sugar automatically changes it to Account_Name_C. This is why I decided to forego the 'out-of-the-box' fields.

    Can I manually add the code for the Account_Name and Last_Name fields to the editviewdefs and detailviewdefs of the modules I want them to show up in?

    Thanks again, Roberto Ruiz

  5. #5
    robertbmirth is offline Sugar Community Member
    Join Date
    Jun 2010
    Location
    Irvine, CA
    Posts
    345

    Default Re: Making a field not 'required'

    Unless you really know what you're doing, you don't want to add code to any of the metadata files. Meta data implies code about code, or basically code defining code. Essentially any file that has 'defs' if the filename is a metadata file and isn't going to help you. These files are all about static definitions (that are often cached so they're not even referenced all the time anyway) and won't help you if you want to populate these fields with dynamic data.

    That being said, if I'm understanding you right, you want to populate fields in related modules whenever you update leads. If that's correct, you can do that through a logic hook. If you're having a hard time populating the account name in the contacts its because its actually populated by an account id as well, which means you'll have to make an account first. So basically what you'll have to do is whenever you update your lead, you write a logic hook that does the following:
    -Looks to see if there's an account by the same name or id (id would be better) as the one in your leads module, if not create it and link it to your leads module
    -Update whatever information in the account you want to update
    -Find whatever related contacts you want to update (this can be done via the load_relationship() function.
    -Update those related records with the account id and whatever information you're updating.

    Metadata and logic hooks aside, if you want a simple way to "fix" your problem, you can prepopulate the "out of the box" required fields with data by modifying the bean class and then continue using your custom fields. Again, this isn't good practice, but it will get the job done. Just go into module/Contacts/Contact.php (or the bean class, the .php file with the singular name of the module, of whatever module you're working with) and find the variables last_name, account_name, and account_id and then just add = "_" before the semi colon. That way, when sugar creates a new Contact, the last_name and account_name will already be filled with a '_' and it won't bug you to fill these fields.

    I'm still not entirely sure why you're making a custom field for information that's already there, but to each his own i guess.
    Robert Beckman
    Software Engineer
    Mirth Corporation

  6. #6
    abhax's Avatar
    abhax is offline Senior Member
    Join Date
    Jun 2010
    Location
    India
    Posts
    65

    Smile Re: Making a field not 'required'

    Hi,


    Issue 1: Making Contact name optional. Well i looked into it and saw that this field is required by Contact n Lead.
    Tried the traditional method of making a field optional in cutom/Extension/modules/contact/Ext/vardefs/
    but failed!


    Issue 2: How to make the Account for Lead Converted optional.
    Well you need to copy the

    modules/Leads/ConvertLead.php
    modules/Leads/ConvertLead.tpl
    into
    custom/modules/Leads/ConvertLead.php
    custom/modules/Leads/ConvertLead.tpl

    in ConvertLead.php

    find all the line echo $sugar_smarty->fetch('modules/Leads/ConvertLead.tpl');
    and change it to echo $sugar_smarty->fetch('custom/modules/Leads/ConvertLead.tpl');


    in the ConvertLead.tpl file in the custom/modules/Leads/
    In the beginning you will find


    <span class="color">{$ERROR}</span>
    <script>
    function isChecked(field) {ldelim}
    return eval("document.forms['ConvertLead']."+field+".checked");
    {rdelim}
    function checkOpportunity(){ldelim}
    if(!isChecked('newopportunity')){ldelim}
    return true;
    {rdelim}


    removeFromValidate('ConvertLead', 'Opportunitiesaccount_name');
    if(validate_form('ConvertLead', 'Opportunities')){ldelim}

    if(this.document.forms['ConvertLead'].selectedAccount.value != ''){ldelim}
    return true;
    {rdelim}
    if(!isChecked('newaccount')){ldelim}
    alert('{$OPPNEEDSACCOUNT}');
    return false;
    {rdelim}
    return true;
    {rdelim}
    return false;

    {rdelim}
    </script>
    {$DUPLICATEFORMBODY}



    Change it to:

    <span class="color">{$ERROR}</span>
    <script>
    function isChecked(field) {ldelim}
    return eval("document.forms['ConvertLead']."+field+".checked");
    {rdelim}
    function checkOpportunity(){ldelim}
    if(!isChecked('newopportunity')){ldelim}
    return true;
    {rdelim}


    removeFromValidate('ConvertLead', 'Opportunitiesaccount_name');
    if(validate_form('ConvertLead', 'Opportunities')){ldelim}

    if(this.document.forms['ConvertLead'].selectedAccount.value != ''){ldelim}
    return true;
    {rdelim}
    if(!isChecked('newaccount')){ldelim}
    //alert('{$OPPNEEDSACCOUNT}');
    return true;

    {rdelim}
    return true;
    {rdelim}
    return false;

    {rdelim}
    </script>
    {$DUPLICATEFORMBODY}


    This will lead you convert the lead without the need of an account for the lead.
    This will solve your second issue.

    If you come to know hoe to solve first issue do all know.



    Hope it is helpful !!!
    If It Is To Be, It Is Up To Me

  7. #7
    mangesh1757 is offline Sugar Community Member
    Join Date
    Jan 2010
    Location
    India
    Posts
    226

    Default Re: Making a field not 'required'

    Hi Neilltech,

    The Accounts optional part is quite achievable within seconds ;-) .

    Please refer link below Post No. # 9,

    http://www.sugarcrm.com/forums/showt...quire_accounts

    Thanks.

    PS : Please stick to approach where one should hardly modify core files, just try to work around to fit within sugar CRM framework in order to prevent huge obstacles in future.
    Last edited by mangesh1757; 2010-10-18 at 04:49 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 13
    Last Post: 2010-12-03, 11:17 AM
  2. Making field one-to-one relationship required
    By kstro21 in forum Developer Help
    Replies: 3
    Last Post: 2010-05-28, 05:24 PM
  3. Making field required based on dropdown
    By cmcassity10 in forum Developer Help
    Replies: 3
    Last Post: 2010-04-23, 11:34 AM
  4. Making fields as a required field
    By dinudanial in forum Developer Help
    Replies: 3
    Last Post: 2009-04-03, 05:12 AM
  5. Replies: 7
    Last Post: 2007-07-13, 01:38 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •