Great work.
This module has opened a lot of possibilities.

I have two questions
1) It appears that we can only create new contacts. But at times we may want to add a Relationship of new Contact1 to an existing Contact2. For example, when Contact1 is created we may want to relate contact1 as Employee of existing Organization. In this example, is it possible to do a select from existing organization?

2) Another thing related to this is, when an existing contact name is entered it updates the existing record. Is there a way in which it can alert if the contact already exists?

Comments

colemanw’s picture

1) Is your database really so small that you can show all organizations in a select drop-down?

2) When you enter an existing contact, it will be matched and updated via civicrm's default strict matching rule. Is this not what you were expecting?

pankaj01’s picture

Thanks for the reply.

1) Good point. No, my database is not that small. The select drop-down is not a good solution, as you suggest. How about "Autocomplete Select" ?
That way it would list the contact (organization name) as the user starts typing. This will work with bigger contacts list as well.

2) Matching an existing record based on civicrm's default strict matching rule is as a I expected. But, updating without alerting can lead to un-intended updates. For example,
2a) A typing error by user would create a new contact. and this will be an issue if he actually intended to update an existing contact.
2b) Again, a typing error can update the data in a existing contact, while his intention may have been to create a new contact.

Consider this, if an organization 'OrgA' exists and I want to add a new relationship with it when creating a new contact. It is safer and easier to choose the OrgA from an Autocomplete-select field instead of an Input field. Otherwise I would have to do a search for the organization name and get the org name and then enter in the form.

Hope this makes sense. And if so, I think it would be simple for you to make this change.

Thanks for this module!

colemanw’s picture

Unfortunately no, it would not be simple. It's also going to take a lot more thought to properly plan for such a change, because:
a) There are major security implications involved in allowing webform users to look up any contact in your database.
b) Drupal's autocomplete is insufficient to such a task, so some custom JS would be needed - it would need to fill-in a hidden cid field, as well as all the other fields for a contact.
c) Deciding which fields to autocomplete would be tricky. Organizations and households have 3 name fields, individuals have 5.

This module was originally created for front-end forms (such as a job application). End users do not care about deduping rules and, in my experience, will make a bigger mess of your database if you give them control over that sort of thing than if you don't (i.e. allowing them to say "this contact is the same as an existing one" is no guarantee that they will choose correctly). If you are creating a front-end form, I highly recommend you stick with what this module and CiviCRM are designed to do, which is to match if it is a sure match, and create a duplicate if there is any doubt -- it's much easier to merge contacts later than to untangle contacts who should not have been merged! If you are getting false-positive matches (as you suggested in your example above) then you should make your strict rule stricter.

pankaj01’s picture

I agree with the reasons you mentioned about it.

The core reason, I guess, for differences in our opinion is because I am trying to use this form for office users (authenticated with right permissions) and NOT for end users(like anonymous). Thus I am looking for organizations list to show up in auto-complete search.

Responses to your points:
a) for security concerns: the form can be access controlled to only users in a Drupal Role.
b) Please give me a clue on this and I would like to try it out.
c) May be, at this point only organizaitons can be made autocomplete-select - may be.

As a work around, if it is possible to make 'External id' an 'unhidden' field then it will help in a way. I can show the external id as a view page in a drupal Block suggesting (office) users to enter external id, instead of organization name to avoid spelling errors. Is it possible to make 'External id' unhidden?

colemanw’s picture

Here's an idea you might like even better. You might remember from the instructions that this module accepts contact ids in the url, i.e. example.com/myform?cid1=123&cid2=456

1) Create a view that lists organizations
2) At minimum, your fields should be contact id (excluded from display) and Display Name (visible)
3) For display name, click "output as a link"
4) Use the token from the contact id field to build the link. i.e. example.com/myform?cid2=[contact_id]

The example above will take the user to a form with contact 2 pre-filled as the org they clicked on. You don't even need any fields for the org on the form if you don't want the user to mess with anything.

One more note - if you wanted your form to add more than 1 employee at a time, consider making the org contact 1 - then you can create contact 2 as the employee and use the "clone" feature to make more employees (you can also clone contact 1, this just seemed easier)

pankaj01’s picture

I don't think I have understood the approach correctly. But it appears to be a smart way. I am trying it out now.

Thank you Colemanw

pankaj01’s picture

It worked.
but I wish I can make a little improvement....
------------------------------------------
I did as you suggested. The results are as expected. But the approach seems a bit roundabout. That is, the Organization has to be FIRST selected from a hyper-linked list (generated by view) which is a page. Clicking on it takes to the form. Then the other details can be entered in the form. I Wish I could make selecting the organization in the same page as form filling.

The good thing is I have a workable solution. And the reason I am expressing my wish is that I feel you enjoy supporting.
Thanks for bringing it to this level.

Another thing that I notice is every new contact gets a Relationship: 'Employee of' the Organization. I have created a new Relaionship Type. But both Relationships gets added. I have not set 'Employee of' relationship. Not sure how it gets added.

colemanw’s picture

Component: Webform/Drupal » CiviCRM Data Handling

Unfortunately, that little improvement would be a big undertaking. I've had several requests for ways to autofill/suggest/choose/guess from existing contacts, but each use case has different requirements and expectations. So far I have not thought of a generalized way to do this that will work well for everyone.

I'm puzzled about the issue of relationships. If you want to contact me with drupal login and ssh access to your server I can troubleshoot.

pankaj01’s picture

I am working on setting up the environment to let you access my server. It would take less than a week to get all things in place.
Nice of you that you are willing to login and check.

laryn’s picture

Category: support » feature

Would it be possible to set up an "Auto-populate fields" checkbox in the Contact info area which opened up to further configuration settings if selected? Further options could include:

  • Which field to autopopulate
  • Where to pull from (e.g. a CiviCRM group, or a particular contact subtype...)
  • Format to display (e.g. select list, autofill...)
colemanw’s picture

Yes this is certainly possible. What's needed to make it happen is a contribution of money or code.
I'd estimate it to be a 10-15 hour project for me @ $100/hr.
Since there are multiple people interested, perhaps the costs could be split if people want to chip in.

petednz’s picture

i have a client interested in a similar outcome.

current scenario is - kids enrol in an after school care program via webform - need to enter 'name of school' - there are only 50 schools so we want to give them a list - doesn't need to be autocomplete - rather than have duplicate school records being created

we could just have the 50 or so schools in the area as a select field but that loses other possibilities

we could use a 'contact reference' field and since there are only 50 options, add those options in the options field in the webform if doing so would then mean that eg Red School would get pushed through to civi which would then add it in the contact reference field

thoughts?

colemanw’s picture

I'm doing something similar with our online app software, which doesn't use webform - it's all custom coded.
To choose their current school, first they choose the state/country, then the list of schools gets populated via AJAX. If their school isn't already in the DB, they can choose "other" and the usual org fields will appear for them to fill out.
Getting something this slick into a webform is not impossible, it just takes time and money.
Is your client willing to sponsor such an improvement?

petednz’s picture

i am talking with them about this - but also obviously having to show them the existing routes that could be taken - so will let you know if/when they give an affirmative - and maybe at least seed an MIH for this

did my suggestion of 'put the same options in to webform field as existing in civicrm field' make any sense?

colemanw’s picture

Yes, and I believe that adding support for the currently unsupported contactref field type would be probably the easiest approach to your issue. I could probably knock it out in a couple hours if your client wants to foot the bill.

petednz’s picture

Even if they aren't happy, I am (and will pay if they don't) - please charge ahead if you think it is that sort of commitment.

colemanw’s picture

I'm suddenly crazy-busy. I could do a simple implementation that creates the field but would require you to manage the options (contacts to select from) yourself. i.e.

123|Bob Smith
456|Sue Jones
789|etc...

You could "semi" automate this by using the activity assignee field to create the list for you, then clone that field, give the clone the right key, and it ought to work fine.
Should take me about 1.5 hours ($150). Let me know if you're still interested.

petednz’s picture

yes pls

homebrewruss’s picture

Hi, we're interested in the functionality described in #10 and would be willing to contribute for a day or two's development time - if that's what it would take.
Do you have any time at the moment to work on something like this? We could create a more accurate spec if so.

Thanks

petednz’s picture

colemanw - not sure if this is an obvious gotcha but using contact reference field from a civi-group - if we change the contacts in the civi group, the ones that show in the dropdown in webform is only updated if we re-save the civicrm 'settings' on the webform

colemanw’s picture

Right. Currently this is implemented with a webform select element, which like all webform fields, does not auto-update. However, assuming all goes well with the project in #19, I will be creating a new webform element type for selecting contacts, which could, with your sponsorship, be extended to also work with contact ref custom fields.

colemanw’s picture

Status: Active » Fixed

These features are now part of the 3.x branch. Enjoy :)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.