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) »
  • Inline editing of custom organisation field like employer field
Pages: [1]

Author Topic: Inline editing of custom organisation field like employer field  (Read 846 times)

VitorFF

  • I post occasionally
  • **
  • Posts: 35
  • Karma: 1
  • CiviCRM version: 4.4.11
  • CMS version: Drupal 7.27
  • MySQL version: 5.5
  • PHP version: 5.4
Inline editing of custom organisation field like employer field
September 01, 2014, 06:47:50 am
Hello,

We are trying to replicate the way the API converts the current_employer contact data field into the employer_id using in-line editing in order to do it in some similar custom data for our brand new dashboard's view & edit contact page.

Right now we have this field working (thanks Coleman!) where we're using in-line editing to set the current employer of a contact:
Code: [Select]
<span id="contact-{$cid}" data-action="create" class="crmf-current_employer crm-editable">{$summary.current_employer}</span>

But in our 'Undergraduate institution'  custom field (custom_49) we are not being able to replicate this functionality:
Code: [Select]
<span id="contact-{$cid}" data-action="create" class="crmf-custom_49 crm-editable custom_49" ></span>     

We have tried to pinpoint where in the API call this conversion is being made to see why our solution is not working and/or if we can replicate it.
We looked it up in these files for the place the conversion is made in order to study it:
#  "all/modules/civicrm/api/v3/Contact.php" civicrm_api3_contact_create();
#  "all/modules/civicrm/api.php"  civicrm_api();
#  "all/modules/civicrm/api/v3/utils.php" civicrm_api3_validate_fields();

But so far we had no luck.

All help and suggestions are much appreciated!

Thanks.
Why don't you take a look at this? (You will not regret it!)

Capitalisation Corrector : https://civicrm.org/extensions/capitalisation-corrector

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Inline editing of custom organisation field like employer field
September 01, 2014, 07:03:32 am
When I just type an api call for this type of thing into my console it works fine, e.g.:
CRM.api('contact', 'create', {id: 214, custom_1: 'Env'});

Take a look in your console to see what ajax call is being fired by the inline-edit, and compare it to the one that gets fired when you just type in a call like the one above.
Try asking your question on the new CiviCRM help site.

VitorFF

  • I post occasionally
  • **
  • Posts: 35
  • Karma: 1
  • CiviCRM version: 4.4.11
  • CMS version: Drupal 7.27
  • MySQL version: 5.5
  • PHP version: 5.4
Re: Inline editing of custom organisation field like employer field
September 02, 2014, 08:07:08 am
Hi Coleman,

Again, thank you a lot for your help so far!

So, this is the data that is being passed on the AJAX call
Code: [Select]
entity:contact
action:create
json:{"id":"32972","custom_49":"Institution Name"}

And the response is this
Code: [Select]
action: "create"
entity: "contact"
error_code: 2001
error_field: "custom_49"
error_message: "custom_49 is not a valid integer"
is_error: 1
type: "integer"

Somewhere it should probably be converting the name into a CiviCRM contact id but it is not.

The one that works, current_employer, finds and saves the employer_id on the contact's data, but we can't find how to replicate these with our education institution field. We've checked and data-action='create' is present.

Thank you one again for all your help!
Why don't you take a look at this? (You will not regret it!)

Capitalisation Corrector : https://civicrm.org/extensions/capitalisation-corrector

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Inline editing of custom organisation field like employer field
September 02, 2014, 08:11:13 am
Ahhhhhhh.
Riiiiiiiight.
Noooooo.

I didn't realize that your custom field was of type "Contact Reference". Yea, you can't do that. A contact reference custom field expects a contact id, not a display name.
You would need to add some extra code that looked up the contact by name and inserted an id.
Try asking your question on the new CiviCRM help site.

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: Inline editing of custom organisation field like employer field
September 02, 2014, 10:45:55 pm
Quote from: Coleman Watts on September 02, 2014, 08:11:13 am
You would need to add some extra code that looked up the contact by name and inserted an id.

I feel like somebody wrote a helper for that recently...

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Inline editing of custom organisation field like employer field
September 03, 2014, 12:27:17 am
Haha yep that was me. It's called entityRef and it works magic... but it's 4.5 only. Sorry guys.
Try asking your question on the new CiviCRM help site.

VitorFF

  • I post occasionally
  • **
  • Posts: 35
  • Karma: 1
  • CiviCRM version: 4.4.11
  • CMS version: Drupal 7.27
  • MySQL version: 5.5
  • PHP version: 5.4
Re: Inline editing of custom organisation field like employer field
September 03, 2014, 01:12:57 am
Thanks for responding Coleman.

We basically want to have a field which behaves like the employer field, so it creates and attaches a contact if there isn't one already, otherwise it just makes it reference the existing one. Do you know where this is done?

Thank!
Why don't you take a look at this? (You will not regret it!)

Capitalisation Corrector : https://civicrm.org/extensions/capitalisation-corrector

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Inline editing of custom organisation field like employer field
September 03, 2014, 01:27:47 am
It's not done. That's the point, the api doesn't currently support this.
Try asking your question on the new CiviCRM help site.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Inline editing of custom organisation field like employer field

This forum was archived on 2017-11-26.