mecachisenros / cf-civicrm

Caldera Forms CiviCRM Integration
GNU Affero General Public License v3.0
30 stars 26 forks source link

Create activity assigned to user #61

Closed twomice closed 5 years ago

twomice commented 6 years ago

I'm trying to have my Caldera form create a CiviCRM activity which is assigned to the logged in user.

I've got activity creation working (see the attached Caldera form, test1-export.json.txt). But is there any way to make it be assigned to the logged in user?

mecachisenros commented 6 years ago

@twomice latest commit 5392f986465715b8f89b705e365ed8669d7a6851 should address your case.

You'll find three new checkboxes (for Target, Source, and Assignee) in the Activity processor, as well as select2 widgets for the same fields at the bottom :)

I haven't fully tested it, so feedback is highly appreciated.

twomice commented 6 years ago

Hi @mecachisenros. Am I using this functionality correctly? The attached very simple form (form2-export.json.txt) has two processors:

But when I submit the form, I get the fatal error "Mandatory key(s) missing from params array: source_contact_id".

I assumed Contact 1 would be the contact for the logged-in user, and that the Activity Source Contact would be that contact. Am I doing it wrong?

mecachisenros commented 6 years ago

@twomice I've just tested the form2 attached but it has no contact processor, that's why you get a missing mandatory key error as there's no contact_id passed to the Activity processor, all entities Activity, Relationship, Case, Group, etc. relay on the Contact processor and they must be linked to a Contact processor.

See attached this example activity-example-export.json.txt and let me know how it goes.

twomice commented 6 years ago

@mecachisenros Actually "Form2" does have a Contact processor (it's the one with id="fp_6509988" in the json), but your example suggests something that "Form2" is missing: actual form fields for the contact's name and email, which are then used in the relevant fields of the Contact processor.

So I tried adding these to my "Form 2", and got good results.

So, 2 questions:

  1. Am I right to guess that we need to have those form fields, and to have their values inserted into the right fields in the Contact processor, in order for the "Auto populate contact data with CiviCRM data if user is logged in." to result in creation of a CiviCRM contact?

  2. If I have two Contact processors on a form, can I use an Activity processor to create an activity that's "with" Contact 1 and "assigned to" Contact 2?

mecachisenros commented 6 years ago

@twomice for some reason the Contact processor didn't show up when I've imported your form.

Back to tour questions:

  1. Yes you are correct, the form fields need to be mapped to the Civi fields in the processor, for both, autopopulation of data (if user is logged in or via checksum), and for Contact creation/update, if those fields ar not mapped, no contact will be created (nor any other entity linked to that Contact processor) as you'll be passing no values to Civi's API, so summarizing, what the processors do is map the form values to Civi's entities through the API if that makes sense.

  2. That's not possible currently, I have not thought of that use case. I think a decorator on the select2 widget (the entityRef-like fields) to add the option to select/link to a Contact processor and the option to set a spcifc Civi contact would be a solution, and I would get rid of the checkboxes at the top, as they would not be needed anymore. Thoughts?

twomice commented 6 years ago

@mecachisenros

  1. Got it. Thanks.

  2. Yes, I think that's exactly the right way: a decorator on the select2 widget (the entityRef-like fields) to add the option to select/link to a Contact processor and the option to set a spcifc Civi contact.

mecachisenros commented 6 years ago

@twomice latest commit against master 93b13f859f0a8ce0401ec10636ced91b62c766a4 should address this. I suggest you clear browser cache.

Let me know if that works.

twomice commented 6 years ago

Super -- will try. Thanks!

twomice commented 6 years ago

Hi @mecachisenros With the latest code, I'm seeing that the Contact ID options (Target Contact ID; Source Contact ID; Assignee Contact ID) are all empty. I'm attaching the form json for reference: example_issue_61-export.json.txt

I'm also getting a JavaScript error which seems to be relevant:

Uncaught ReferenceError: cfc_select2_defaults is not defined
(anonymous function) @ VM1111:24
(anonymous function) @ VM1111:23
i @ jquery.js?ver=1.12.4:2
j.fireWith @ jquery.js?ver=1.12.4:2
n.extend.ready @ jquery.js?ver=1.12.4:2
K @ jquery.js?ver=1.12.4:2

... even though the admin.js file seems to be loaded correctly: http://[example.com]/wp-content/plugins/caldera-forms-civicrm/assets/js/admin.js?ver=0.4.2

function cfc_contact_link_options( id = null ) {

    var options = [];
    for ( var i = 1; i <= 10; i++ ) {
        options.push( { id: 'contact_' + i, text: 'Contact ' + i } )
    }

    if( ! id ) return options;

    return options.filter( function( option ) {
        return option.id == id;
    } ).shift();
}

function cfc_select2_defaults( selector, value ) {

    if ( value ) {
...etc...

Can you suggest something I can do on my side, or is this an issue in the code that you can address?

Thanks, Allen

mecachisenros commented 6 years ago

@twomice I don't see what can be wrong, I've just tested on a clean Civi/WP install to double check, but I cannot reproduce the error.

There was a missing semicolon but that shouldn't have affected it, I've created a new release, can you try pulling master again, with the version bump WP should load a fresh copy of the admin.js file.

Also, can you check the call stack to see where/what might be causing it, maybe another plugin or select2 version (the latter is more unlikely, I've address it a few commits back, but it can be a possibility).

twomice commented 6 years ago

Thanks, I'll look at it again.

danaskallman commented 6 years ago

Just to make sure I am understanding correctly, am including screenshot of the select assign to contact in the processor. I added two contacts to a form, and added the activity processor and used the following to assign to contact 1 and 2. Is that the goal?

activity-contact-connection

twomice commented 6 years ago

@mecachisenros Yes, that's what I expected to see. So it looks like the issue is that those three select2 controls are not being populated at all, probably due to whatever is causing that JS error. I'll look further and update the ticket here.

twomice commented 6 years ago

@mecachisenros OK, found the cause of the error. It was actually caused by an older browser lacking support for ES6-style default parameters. See https://github.com/twomice/caldera-forms-civicrm/commit/5007909c1689d75a8f2bfd350be192360b4f919b for the relevant line. This is an outdated browser, so I'm not submitting a PR; just documenting for posterity.

twomice commented 6 years ago

@mecachisenros And, to report on the new feature: Yes, it works great and has the intended effect: I can configure an Activity Processor so that the Assigned, With, and Target contacts are all references to the contact in a Contact Processor. Thanks!

One small usability issue is not a deal-breaker for me, but reporting as feedback: When selecting one of these contacts, as in this image selector I'm unable to select Contact 1 without first selecting another contact and then changing it back to Contact 1. I think that's because the selection is tied to the "change" event, and "Contact 1" is the default value. I.e., I have to select "Contact 2", then select "Contact 1".

mecachisenros commented 6 years ago

@twomice Ha! You start using ES6 new features and give them for granted...

I'll amend both default parameter and usability issue in the next release. Thank you for the feedback.

twomice commented 6 years ago

:-) Yeah, sad thing ES6 isn't so "new" anymore. But yeah, thanks for the continued improvements.

mecachisenros commented 5 years ago

@twomice I've removed the default parameter, and the usability issue should be fixed as well. Feel free to reopen if there's anything else missing.

twomice commented 5 years ago

Thanks!