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 »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • crmAutocomplete Not Responding to Params
Pages: [1]

Author Topic: crmAutocomplete Not Responding to Params  (Read 667 times)

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
crmAutocomplete Not Responding to Params
May 26, 2014, 08:27:07 am
The code on http://en.flossmanuals.net/civicrm-developer-guide/api/ :

Code: [Select]
jQuery(document).ready(function($){
  $('#current_employer').crmAutocomplete({params:{contact_type:'Organization'}});
});

returns also Individuals on a Drupal 7 / CiviCRM 4.4.4 site that I am working on. The URL being fetched is

civicrm/ajax/rest?rowCount=35&json=1&entity=Contact&action=getquick&sequential=1&params[contact_type]=Organization&s=robinson&limit=25&timestamp=1401117553940&name=Robinson

In the API explorer, this URL

/civicrm/ajax/rest?entity=Contact&action=get&debug=1&sequential=1&json=1&contact_type=Organization&state_province_id=1644&sort_name=Rob

finds only two Organizations and if I remove the contact_type=Organization part:

/civicrm/ajax/rest?entity=Contact&action=get&debug=1&sequential=1&json=1&state_province_id=1644&sort_name=Rob

then it finds 25 Contacts, including the Individuals. So that part works.

But crmAutocomplete is not working for me. :(
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: crmAutocomplete Not Responding to Params
May 26, 2014, 09:35:12 am
Hi,

Can you try

$('#current_employer').crmAutocomplete({contact_type:'Organization'});

instead of
$('#current_employer').crmAutocomplete({params:{contact_type:'Organization'}});
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: crmAutocomplete Not Responding to Params
May 26, 2014, 10:15:22 am
URL is

/civicrm/ajax/rest?rowCount=35&json=1&entity=Contact&action=getquick&sequential=1&contact_type=Organization&s=robinson%2C+h&limit=25&timestamp=1401124341283&name=Robinson%2C+H

Still brings up Individuals. :(
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

joanne

  • Administrator
  • Ask me questions
  • *****
  • Posts: 852
  • Karma: 83
  • CiviCRM version: 4.4.16
  • CMS version: Drupal 7
Re: crmAutocomplete Not Responding to Params
May 26, 2014, 03:56:37 pm
http://wiki.civicrm.org/confluence/display/CRMDOC/API+Reference is where you will find the most up-to-date developer documentation. 

It may not vary from the out-of-date documentation in this case (haven't checked), but you should know for the next time.

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: crmAutocomplete Not Responding to Params
May 27, 2014, 03:37:35 am
joanne, I don't understand how your answer is supposed to help. I see no docs for crmAutocomplete on the wiki. Not via a search on the wiki itself nor via a search on Google.

Please read the full thread above. I am looking to get crmAutocomplete to work as advertised. If you know the format or a specific page with this information, please let us know.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

joanne

  • Administrator
  • Ask me questions
  • *****
  • Posts: 852
  • Karma: 83
  • CiviCRM version: 4.4.16
  • CMS version: Drupal 7
Re: crmAutocomplete Not Responding to Params
May 27, 2014, 06:39:34 am
I wasn't saying that my post was going to provide a solution to your problem, in fact I specifically said
Quote
It may not vary from the out-of-date documentation in this case (haven't checked)

I had noticed that your first post referred to documentation that is no longer maintained (http://en.flossmanuals.net/civicrm-developer-guide/api/) and just wanted to alert you to the fact that the most up-to-date documentation is now at http://wiki.civicrm.org/confluence/display/CRMDOC/API+Reference 
Quote
you should know for the next time

The switch to the wiki happened around the end of 2013 with Erik Hommel transferring and updating the API section I believe. The book version you are referring to would date from about 12 months ago I think.

If there are sections in the no-longer-maintained book that contain up-to-date information that is missing from the wiki please create a documentation issue on Jira with the details.
« Last Edit: May 27, 2014, 06:43:09 am by joanne »

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: crmAutocomplete Not Responding to Params
May 28, 2014, 11:17:37 am
I see in api/v3/Contact.php line 628:

Code: [Select]
  if (CRM_Utils_Array::value('org', $params)) {
    $where .= " AND contact_type = \"Organization\"";

I have no idea why that is the code, but if I use

Code: [Select]
$('#current_employer').crmAutocomplete({org:1});

it indeed works. Not a surprise. :)

Next mystery. My actual code is:

Code: [Select]
$('#current_employer').crmAutocomplete({org:1,state_province_id:$('#state_province-Primary').val()});
to get only Orgs from that state. The state_province_id is not included in the SQL query that is used in the code however. :(

So I added the second if statement here:

Code: [Select]
  if (CRM_Utils_Array::value('contact_sub_type', $params)) {
    $contactSubType = CRM_Utils_Type::escape($params['contact_sub_type'], 'String');
    $where .= " AND cc.contact_sub_type = '{$contactSubType}'";
  }

  if (CRM_Utils_Array::value('state_province_id', $params)) {
    $state_province_id = CRM_Utils_Type::escape($params['state_province_id'], 'Integer');
    $where .= " AND state_province_id = '{$state_province_id}'";
  }

at around line 662. This appears to work.

The only problem is that if you change the State dropdown it doesn't change the search parameters, due to how the parameters are passed statically to crmAutocomplete but anyhow this appears to be a step in the right direction. :)
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: crmAutocomplete Not Responding to Params
May 28, 2014, 11:29:59 am
PS: Issue filed: https://issues.civicrm.org/jira/browse/CRM-14762
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • crmAutocomplete Not Responding to Params

This forum was archived on 2017-11-26.