Viewing/searching on fields from related modules

We have a custom module, Plans, for which we have set up a 1 to 1 relationship with the Leads module.

We would like to be able to filter on, and also display (both in the listview and the detail record) some of the additional fields from either related module.

As an example, the Plan module has a text field, Gcode. When filtering the Leads, we would like to be able to filter on the Gcode from the related Plan record, display this Gcode in the resulting listview and also see it in the detail record (but do not want to be able to edit it.) We also want to do vice versa with some custom fields from the Leads module.

Could anybody recommend a good way of being able to do this and, if it is via custom code, suggest a good example that we could follow? (What we have done up until now is create an additional GCode field within the Leads module and update it via a workflow however this hasn’t been entirely reliable. We particularly want to ensure that if a Leads/Plan combination are unlinked, the Leads GCode is returned to blank.) Is there possibly some add-on that would enable us to do this? (I would have thought it was a common requirement.)

I have seen a couple of articles on-line that describe some of what we need to do but we are unfamiliar with custom coding and I have found them a bit confusing for a beginner. We did get a search of a related field to work on 2 different related non-custom modules by following

however we haven’t yet managed to get it working on our custom module and partly I was wondering what was the best approach if we need to be able to do all three, ie
  • Filter on related module’s field
  • Display related module’s field in list view
  • Display related module’s field in detail view

You can look at the post for filter:

I don’t have a ready decision for listview but I think that you can make modified function preDisplay in: custom/modules/Leads/views/view.list.php (similarly for detailview).

Thank you very much indeed for taking the time to reply, it is much appreciated, we’ll give it a go.

1 Like