SugarCRM: Making Fields Required But Not Hidden

Posted by on January 26, 2012 in Development, PHP, SugarCRM, Tips and Tricks | 4 comments

Welcome to the first Jon’s Tips and Tricks for SugarCRM.  In this post I’m going to cover how make fields required when other fields equal something specific.  Now I know what you are going to say, “This is available in studio” and while it is, it will hide the field on the edit view when you don’t have the values selected/set in the specific control fields.

This is done though a vardef (variable definition) extension in Sugar and it’s an upgrade safe customization.

Here we go:

1. Start by making sure the file path exists: custom/Extension/modules/<modulename>/Ext/Dependencies/

2. Create a new file (descriptive file name is best so you know what it does just by looking at the file name).  Mine is called primary_address_postalcode_required.php

3. Here is my code:

SugarCRM Information

  • Version: 6.1+
  • Editions: Pro, Corp, Ent, Ult
  • Difficulty: 2

SugarLogic Method Information

Let me break apart the value param and explain it what each one does:

      • and() – a simple way to tie multiple command together, this can have 2 or more sub commands in it.
      • equals($field, “value”) – a quick and dirty way to say that $field is equal to “value”
      • isInList($field, $list) – a way to say that $field’s value is in a list.
        • for the list you can do two things
          1. createList($value, $value1, …) which will create a list on the fly but to update the values if need you need to do a code change
          2. getDropdownKeySet($list_name) will return the keys from a drop down list.  What is allows you to do is create a new list in the drop down editor and it allows anyone who has access, to add or remove values without having to make code changes.
For more information check out the developer docs

4. Once that is done you put it on your server and run a repair and rebuild.

5. Go about your day have better data quality due to making fields require when other specific values are set.

Cheers!

4 Comments

  1. Nice hint Jon!

    ps: I would suggest you add the supported sugarcrm version of your tricks… is this only professional or CE version?

    pura vida

    • Excellent, Idea. I will figure out a way do this that works and I’ll add them.

  2. You mention “ugarLogic for it to trigger”. Does that mean this does not work with CE?

    • AJ,

      Currently, No, as SugarLogic is Pro and above only.

Leave a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Fork me on GitHub