Normally when you add a check-box field to the basic search it displays it as a drop-down rather than a check-box. This was an annoying issue as I wanted a check-box to be displayed. You will notice that the My Items check-box is displayed correctly in the basic search layout so there must be a hard coded check somewhere that looks for current_user_only or Open Items and makes them stay a check-box.

After a bit of searching I found the code in include/SugarFields/Fields/Bool/SugarFieldBool.php line 55. It appears that all I had to do was pre-pend my field name with open_only and it would remain a check-box rather than a drop-down field.

Don’t forget to at the label to the language file in: custom/Extension/modules/Events/Ext/Language/en_us.Events.php

$mod_strings ["LBL_EVENT_FUTURE_ONLY"] = "Display future events";

Step 2:

Now that the check-box is displaying correctly in the basic search layout at the top of the Events ListView I had to actually make the search filter work by only displaying upcoming future events in the ListView when it was checked. After a little research and a lot of pouring over the code this turned out to be simpler than I thought.

All I had to do was add a simple subquery to the SearchFields.php file like so:

By setting the query_type to format and adding OR NOT {0} to the end of the query you are telling the filter to use the open_only_future_events check-box value in the {} and to ignore it if its {0} (not checked).

That’s pretty much all that was involved in getting this working however it took quite a bit of effort to figure this out hence the post.

Out the box SuiteCRM and SugarCRM CE do not allow searching from related modules with a many to many relationship. But this can be overcome by adding a custom relate field that represents your relationship then using a custom sub-query in SearchFields.php.

Step one add the relate field:

Create a file for the module you want to add the non-db related field in the custom extension vardefs:

The custom relate field representing our relationship should now be available to add to the search layouts via studio and and return the correct search results. However this will not work if you need to add the field to the popupview search.

Searching on relationships is one of the big shortcomings in Sugar. Once you do get it to work for the main search results, it is likely to break if you use the pagination or Mass Update on those search results.

This is similar to what we are seeing with the popupview search. The back end doesn’t use a unified method of searching. It’s a different stack of calls depending on where you are. Very frustrating. What this means is that you can’t always get something on the list view/searches to work across to other areas like the popup view.

I struggled with this for a while then is was suggested to me to customise the view.popup.php for the module and jam in the condition if being searched on in $popupMeta[‘whereStatement’] within display().

Adding the many to many search to the Popup View

custom/modules/Contacts/views/view.popup.php

Inside the view.popup.php for Contacts there was an updatePopupMeta() function. Inside this function I added the following:

This adds the required sub-query onto the where statement in the popup filter if mode equals ‘MultiSelect_fp’. I also had to customise the open popup JavaScript to pass in the required search parameter for the popups initial filtering: $_REQUEST[‘metadata’]

In my last post I showed you how to make specific fileds for specific modules mass up-datable but what if you want to make a field type mass up-datable across all modules? In the following tutorial I have used text fields as an example.

Before we start I want to make it clear that this is a Non-Upgrade Safe modification.

By default SugarCRM only allows fields of the following types to be mass up-datable :

Bool

Enum

Multienum

radioenum

datetime

date

So if you want add non mass up-datable fields or custom fields to the mass update form then you have to make some non-upgrade safe changes to the following file:

include/MassUpdate.php

Edit the getMassUpdateForm() function and add the code after this comment

Now if we update the vardefs for a specific text field and set ‘massupdate’ => true the field will appear in the mass update panel of the module but that’s not enough if we want system admin users to be able to add text fields to the mass update panel of a module via studio.

In order to achive this all we need to do is edit: modules/DynamicFields/templates/Fields/Forms/varchar.tpl

The next thing we need to do is set the massupdate parameter to true in the vardefs for the field.

If its a custom field that you added through studio then simply go into your sugar database and then the fields_meta_data table and find the row entry for your custom field.
Change the massupdate field from 0 to 1.

If its not a custom field added through studio then create a custom php file in this location:

There may come a time in the development of a custom SuiteCRM or SugarCRM module when it would be handy to store additional data in the relationship table between two modules. This is not possible in studio or module builder and is not that straight forward even for an experienced coder unless you have a deep understanding of sugar’s underlying architecture.

So Ill save you the headache I had when first trying to implement this type of modification.

Step 1

The first thing you need to do is define your new fields in the metadata for the relationship. I will be adding the field in the relationship between a custom module FP_events and Contacts. The relationship fp_events_contacts is a many to many and the subpanel ill be displaying the field in is the contacts subpanel on the FP_events module.

This file can be found at:

custom/metadata/fp_events_contactsMetaData.php

In the code below notice that I added a field called ‘date_cancelled’ with type ‘date’ to the fields array.

Once you have added your desired fields to the fields arrays do a quick repair and rebuild from the admin panel of Suite or Sugar and then execute the suggested sql queries this will add the fields to the database table for the relationship. (I double checked that the fields were added by going into phpmyadmin and looking at the fp_events_contacts_c table.)

Step 2

Your fields are now defined and in the actual database table but your only half way their if you want your fields to actually be displayed in the subpanel. The next thing you want to do is define your new fields in the vardefs for the relationship. This is done by adding a file in the custom/Extensions folder like so:

custom/Extension/modules/Contacts/Ext/Vardefs/CAN_BE_ANY_NAME.php

In this file add the following three definitions for each field your adding. Pay careful attention that all the field names and ids match up between definitions as minor typos here will prevent the fields from showing in the subpanel and can be major pain to spot:

In the code below notice that I add my field event_cancelled (as defined in the step 2 vardefs) to list_fields array and further down in the array I also add ‘e_date_cancelled’ and ‘cancelled_id’ and mark their usage as query_only.

Now do another quick repair and rebuild from the admin panel and your custom relationship fields should now be showing up on the subpanel. You will now be able to add data into these fields in your module controller either via queries or through sugar’s bean framework.

Note you might have to manually go into the database and add some dummy data into those fields to confirm they are showing (Assuming you have not yet added any data to your new fields).

I recently had a SugarCRM project which had a requirement to make a Select field read only depending on the current users role. The requirment was that if the currenlty logged in user was in the Admin or Admin Manager role then they would be able to see the full select box in the edit view of the module. Otherwise they would only see the current value of the field and therefore not be able to change the field at all.

In order to achive this I first had to create a custom viewEdit file for my module like so:

custom/modules/[your_module]/views/view.edit.php (if this folder does not exist just create it and the file)

The above code gets the currently logged in users roles and checks if the user is in the Admin or Admin Manager role if not it then assigns a value of ‘readonly’ to a variable called ReadOnly and passes it to the smarty template.

We then have to create a customCode field in the editviewdefs that checks if the ReadOnly variable is set to readonly and if so only displays the value otherwise it displays the full select box:

custom/modules/[your_module]/metadata/editviewdefs.php

(If this folder and file does not exist just go into studio and make a small change to the edit view layout for your chosen module and save it. This will create the custom metadata files for the module)

Scroll through the editview defs and find your field in the array then add the ‘customCode’ attribute below the lable like below.