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) »
  • Support »
  • Using CiviCRM (Moderator: Dave Greenberg) »
  • Custom data using data existing within CiviCRM
Pages: [1] 2

Author Topic: Custom data using data existing within CiviCRM  (Read 3252 times)

rolevine

  • I’m new here
  • *
  • Posts: 13
  • Karma: 0
Custom data using data existing within CiviCRM
August 15, 2010, 06:23:07 pm
Hi,

Our entity (parent organization) is a collection of clubs (organizations) and within each club there are members (individuals).  I've successfully created and used several custom data fields for each individual.  So far though I cannot figure out to create as a custom data field a Choice List for each member so that he/she can pick the club to which they belong.  Since the member clubs are all in the civicrm_contact table in the database I was hoping that I could create a custom field based on a specific criteria from that table.  Is this possible?  Please say it is...

Kind regards,
Rob

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Custom data using data existing within CiviCRM
August 15, 2010, 11:16:07 pm
Hi Rob,
so basically you want a list of organisations in the club to be displayed for a user? Perhaps you could make each club a group as well? Then the standard CiviCRM functionality would solve your problem? And you could also very easily create a list of all members of a club.

Erik
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

rolevine

  • I’m new here
  • *
  • Posts: 13
  • Karma: 0
Re: Custom data using data existing within CiviCRM
August 16, 2010, 06:11:58 am
Hi Erik,

I'm not sure I understand.  The organizations from which I want the user to choose are all in one group named "Member Clubs".  I want to be able to add a custom data field to the Individual profile form that will display a select list where its data is extracted from a civicrm table using specific criteria (e.g., select all rows from civivrm_contacts where type = 'Organization' and group = 5).  I do not see how one does that in the current (3.2) functionality for custom data fields.

Kind regards,
Rob

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Custom data using data existing within CiviCRM
August 16, 2010, 06:50:53 am
I understand your question, and I do not see any possibility using standard 3.2 either. You could ofcourse write a bit of custom code, but I thought it might be easier to use the group or tag functionality. So if every club is also a group or tag in its own right, and you have for example 'club red', 'club yellow' and 'club green' , the user can then select what club he or she belongs to from the list of groups or tags. Tags might even be better, with a tag 'Club' and a child tag for every club?
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Custom data using data existing within CiviCRM
August 16, 2010, 07:40:56 am
You can add a custom field contact reference.

By default, it contains all the contacts, but you can modify it

http://civicrm.org/blogs/xavier/how-customise-contact-reference-custom-field

X+

P.S. as with any autocomplete field, the user needs to have civicrm enabled. Probably not rocket science to develop something to have more specific access rights, but right now hasn't been found necessary enough to get funded.
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

rolevine

  • I’m new here
  • *
  • Posts: 13
  • Karma: 0
Re: Custom data using data existing within CiviCRM
August 16, 2010, 09:38:54 am
Hi Erik and Xavier,

I think I like Xavier's solution better because the organizations are going to change and new ones are going to be added so I'd rather not have to require that each time you add a new org that you have to set up a new group.

I will try your solution and let you know.

Regards,
Rob

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Custom data using data existing within CiviCRM
August 16, 2010, 10:04:07 am
I like Xavier's solution better too.....but what do you expect, he is after all a Forum God  ;)
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

rolevine

  • I’m new here
  • *
  • Posts: 13
  • Karma: 0
Re: Custom data using data existing within CiviCRM
August 16, 2010, 11:54:52 am
Hi again,

I took a look at the link and tried to implement it and am missing some piece of the puzzle.  This is the first programmatic custom field I've created so please be kind :).

I created my own CustomData.tpl and put it in a new directory /media/civicrm/custom/templates/ and then using the Global Setting pointed the Custom Templates directory to that new directory.  Unfortunately there is no difference in the behavior of the autocomplete in the UI as it still contains all the contacts.   So I'm guessing that it's some combination of wrong file or code in the file.  Here's the code I used (copied/pasted from the wiki link and _tried_ to update to correspond to my data).  I've bolded the areas that I changed.  I honestly wasn't sure what "custom_field_set_id" is, so I assumed it is the database table that contains the set of custom fields.   One strange thing I did notice after visiting the html source was the the custom input field had a -1 in its name, such as "custom_9_-1"

  jQuery(document).ready(function($) 
  { 
    var customGroup = "#civicrm_value_additional_member_data_2";//name of the table storing the custom fields
    var groupID = 2;// id of the group containing all the member clubs

    // the id of the custom fields change between calls, that's always in the form
    // custom_{id of the field}_{a number that changes based on the moon's phase or something}.
    //In our case, the custom field id is 9, so the id is going to be custom_9_, custom_9_2, custom_9_5 ...
   
    customid=$(customGroup + " input:first").attr('id');
    t=customid.split("_");
    suffix =  "_"+t[2];

    //first take out the default autocomplete that contains all the contacts,
    // and replaces it with one that contains only a subset,
    $("#custom_9"+suffix).unbind().autocomplete(
      "/civicrm/ajax/rest?json=1&fnName=civicrm/contact/search&contact_type=organization&group[2]=1",
    {
     dataType:"json",
     extraParams:{sort_name:function () {return $("#custom_9"+suffix).val();}},
     formatItem: function(data,i,max,value,term){ return value;},
     parse: function(data){
         var acd = new Array();
         for(cid in data){
           acd.push({ data:data[cid], value:data[cid].sort_name, result:data[cid].sort_name });
         }
         return acd;
     },
       width: 500,
       delay:50,
       max:200,
       mustMatch: true,
       autoFill:true,
       selectFirst: true
   )};
)};

Any help is greatly appreciated.

Kind regards,
- Rob

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Custom data using data existing within CiviCRM
August 16, 2010, 12:26:15 pm
Put at text (my favorite AAAAAAAAAAAAAAAAAAAAAAAAAAAA) at the top of the template

If you don't see it, you haven't configured properly the custom template directory in the admin. Not sure, give full path, try again, be sure that your server has access to it.

If you see it, check with Firebug if you have a javascript error message.

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

rolevine

  • I’m new here
  • *
  • Posts: 13
  • Karma: 0
Re: Custom data using data existing within CiviCRM
August 16, 2010, 12:50:53 pm
Hi,

Thanks for the suggestions.  I added "AAAAAAAAAAAAAAAAAA" above the

  jQuery(document).ready(function($) 
  { 

and nothing showed up in the UI.  Even though I'm sure I configured it according to the directions I found a "foolproof" way to test that theory.  I know with 100% certainty that the "Temporary Files" directory works (because I see some csv files that I used for import) and so I put the CustomData.tpl file there and then went into Global Settings and copied the value from the "Temporary Files" input box and pasted it to the "Custom Templates" input box and saved and unfortunately it still does not work and I see no "AAAAAAAAAAAAAAAAAA".

Also there are no Firebug errors, which is not surprising since I didn't see the "AAAAAAAAAAAAAAA"

Any further ideas?  Is there some sort of cache I need to clear or something I need to refresh to get the template to be recognized?

Kind regards,
Rob

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Custom data using data existing within CiviCRM
August 16, 2010, 01:27:19 pm
Hi,

You need to respect the structure ie templates/CRM/Form/...tpl not directly under tempates.

I'd suggest you to read the chapter about extending, will probably save you time.

http://en.flossmanuals.net/CiviCRM/DevelopTemplates

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

rolevine

  • I’m new here
  • *
  • Posts: 13
  • Karma: 0
Re: Custom data using data existing within CiviCRM
August 16, 2010, 03:55:47 pm
Alrighty then, we're getting there.  After setting up the server pathing correctly I ran into a rather annoying issue of template caching that was resolved by deleting the <JOOMLA_ROOT>/media/civicrm/templates_c directory each time I made a change to the TPL file.

But now I'm confused again.  And I have to be honest that this one has puzzled me from the beginning because I didn't understand how replacing the CustomData.tpl wouldn't cause the code to ignore my other custom fields in the same group.  Once I created a CustomData.tpl file that was free of errors and refresh the profile screen I no longer see the Custom Data Field Set (the tab) in the UI.  I did a comparison of the HTML source in the case in which I use the CustomData.tpl and the case where I don't use any custom template.  The html generated while using with the custom template has both the tab and its four custom data children completely missing.  I then get an error about showTab not being defined.

So my guess is that instead of _replacing_ the standard CustomData.tpl I need to supplement it by telling it to use this particular code for just that one field. 

Thoughts?

Kind regards,
Rob

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Custom data using data existing within CiviCRM
August 16, 2010, 03:59:14 pm
Yes, that's code to add at the top, you keep the rest identical.

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

rolevine

  • I’m new here
  • *
  • Posts: 13
  • Karma: 0
Re: Custom data using data existing within CiviCRM
August 16, 2010, 04:27:25 pm
And on to the next next error.

"customid is not defined" javascript error while trying to display the profile page.  My guess is that I don't have customGroup set to the correct value.  In the custom template code you provided there is the line "var customGroup = "#Your_custom_field_set_id";"   As I mentioned before I used the name of the database table that the custom fields are stored in because that's the only thing that made sense to me at the time.  Unfortunately that doesn't seem correct. As the calculated value of customid is apparently null after the line  customid=$(customGroup + " input:first").attr('id');

Can you be more specific as this is my first time with this particular task as to what should go on the right side of "var customGroup"?

Kind regards,
Rob

rolevine

  • I’m new here
  • *
  • Posts: 13
  • Karma: 0
Re: Custom data using data existing within CiviCRM
August 16, 2010, 04:33:30 pm
Never mind I figured it out.

It needed to be "customData2" in my case (at least it seems to get past the javascript error).  I discovered this by looking at the HTML source:


<div id="customData2" class="crm-accordion-body">

Still going...

- Rob

Pages: [1] 2
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM (Moderator: Dave Greenberg) »
  • Custom data using data existing within CiviCRM

This forum was archived on 2017-11-26.