CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • How to control Custom Field in Advanced Search?
Pages: [1]

Author Topic: How to control Custom Field in Advanced Search?  (Read 2668 times)

syntetik

  • Guest
How to control Custom Field in Advanced Search?
October 19, 2009, 04:24:07 am
When I create a custom field, at the bottom is one option: View Only? and the description bellow it - Is this field set by PHP code (via a custom hook)...

So the question is - how to control it? I want to customize Advanced Search panel and added select box for Activities, so that I can search contacts, who are acting in activities, where custom field contains something I select.

For that kind of custom field there is no records in table civicrm_option_value. I simply add arrays with names and values for HTML_QuickForm_Select Object, so I see select box filled with values I needed. I checked whole $form->_elements and my injections standed in right place for form.

But I think it is not right way to be friendly with CiviCRM.

Another question - after submitting advanced search form I see the yellow frame with query... No matches found for: ... and there is my custom field too. But, how the system can find right records, if for this custom field there is no records in civicrm_option_value table??

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: How to control Custom Field in Advanced Search?
October 19, 2009, 07:04:40 am

I assume u r modifying the form with the hook_buildForm

if so that is fine and is the recommended way of doing it

You should check the query (from your query log) to see what the system is trying to search for. that will give you and us a better idea

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

syntetik

  • Guest
Re: How to control Custom Field in Advanced Search?
October 20, 2009, 06:31:58 am
Yes, it is buildForm where I'm moving things.

I don't understand your phrase - You should check the query from your query log. Where it is? Did you mean MySQL log?

Another question - can I insert or modify SQL query (or somehow add criterias and tables for search) after search form submitted and query formed, but before it is executed? I want to add table with LEFT JOIN and add some criteria after WHERE.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: How to control Custom Field in Advanced Search?
October 20, 2009, 10:10:05 am

1. yes, i meant mysql.log

2. no, there currently are no hooks to modify the search query. What your use case for modifying the query? Note that you can potentially modify the query by using the acl hooks

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

syntetik

  • Guest
Re: How to control Custom Field in Advanced Search?
October 20, 2009, 02:44:07 pm
I have table with foreign key to activities - when I create new activity, from select box I select one of items. The ID of it and the ID of new activity are stored in my table. So I need to use Advanced Search to find activities with specified item in the same select box.

If I defined custom field as View Only (to set options with PHP as I told earlier). In Activities pane of Advanced Search then appears this custom field with my options. It's okay, but this field is not available in "New Activity" form. Therefore I deleted my custom field and define select box element from buldForm hook ($form->add...) and store values in additional table.

If you can give an example how to add options to selectbox (custom fields) in both places - Advanced Search and New Activity, maybe it will be simplier to search and then I don't want to modify SQL query.

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: How to control Custom Field in Advanced Search?
October 20, 2009, 05:14:09 pm
Not sure I understand completely what you're trying to do BUT.... if you want a custom field where the <select> options are populated programmatically (from another / external table for example) - you can create a "normal" custom field "used for" Activities with HTML Type = Select and "searchable" checked. Then use customFieldOptions hook to populate the select options for that field.

http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+hook+specification#CiviCRMhookspecification-hookcivicrmcustomFieldOptions
Protect your investment in CiviCRM by  becoming a Member!

syntetik

  • Guest
Re: How to control Custom Field in Advanced Search?
October 21, 2009, 03:30:10 am
Okay. I tried again with custom fields and customFieldOptions hook and all is working well for Activities. New Activity form is okay, Advanced Search is okay. And when I search contacts, it works good. Thank you! I simply don't saw this hook in documentation 8)

But now I want the same thing in Events. I created new custom field for Events. When I create new Event, this field is there and I can select option. But it doesn't appear in Events pane of Advanced Search.

In CRM\Event\Form\Search\advancedsearchpane.tpl there is no includes to show custom fields. And no includes in CRM\Even\Search\common.tpl.

I tried to add something (advancedsearchpane.tpl):
Code: [Select]
{if $validCiviEvent}
    <div id="participantForm" class="form-item">
    <table class="form-layout">
        {include file="CRM/Event/Form/Search/Common.tpl"}
        <tr>
           <td>
               {include file="CRM/Custom/Page/CustomDataView.tpl"}
           </td>
        </tr>
    </table>
    </div>
{/if}
...but it doesn't work. This include I've get from CRM\Activity\Form\activity.tpl.
It seems that custom data are not generated at this step, when building Event search form. How to do that?

Adding {include file="CRM/Custom/Form/CustomData.tpl"} at the top of template doesn't help.
« Last Edit: October 21, 2009, 03:52:19 am by syntetik »

Yashodha Chaku

  • Forum Godess / God
  • Ask me questions
  • *****
  • Posts: 755
  • Karma: 57
    • CiviCRM
Re: How to control Custom Field in Advanced Search?
October 21, 2009, 04:53:53 am
Currently, We do not support search on the basis of event custom data.
Potentially, a custom data section should be added to the Manage Events form,
contributing code for the same would be awesome :)

-Yashodha
Found this reply helpful? Contribute NOW and help us improve CiviCRM with the Make it Happen! initiative.

syntetik

  • Guest
Re: How to control Custom Field in Advanced Search?
October 21, 2009, 08:41:40 am
Very sad! It's time to start support :)
I will check and try some ideas.

How about Reports? It seems that in reports we cannot add criteria with custom fields. Am I right?

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: How to control Custom Field in Advanced Search?
October 21, 2009, 02:56:42 pm
Custom field support has been added to Contribution reports in 3.0. You can use that as a model if you want to work on adding for some other report(s).
Protect your investment in CiviCRM by  becoming a Member!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • How to control Custom Field in Advanced Search?

This forum was archived on 2017-11-26.