Support

Home Forums Event Espresso Premium Mapping Custom Questions to Infusionsoft

Mapping Custom Questions to Infusionsoft

Posted: September 22, 2017 at 11:26 pm


Mike Doughty

September 22, 2017 at 11:26 pm

Hi,

We are using EE4, and I’ve tried editing the code to map a custom question for “company” in the registration form so that it updates the Company field in Infusionsoft.

I’ve followed the instructions on the article
https://eventespresso.com/wiki/infusionsoft-integration/#ee4installation

However it’s a bit vague in regards to whether the text “custom-question” through out the code needs to be edited. And the greyed out instructions seem to say the same thing twice – which is a bit confusing, ie “get the last answer this attendee provided to the question with admin”

Here is the sample code you’ve provided that I’ve edited, can you tell me which part I’ve missed editing to make this work.


* Filters the $is_contact_data before it's sent to infusionsoft
 * in order to add the last registration's custom question answers
 * @param array $is_contact_data
 * @param EE_Attendee $ee_attendee
 */
function ee_infusionsoft_save_my_custom_questions( $is_contact_data, $ee_attendee ) {
    if( $ee_attendee instanceof EE_Attendee ) {

        //get the last answer this attendee provided to the question with admin label 'company'
        $website_answer = EEM_Answer::instance()->get_one( array( array( 'Registration.ATT_ID' => $ee_attendee->ID(), 'Question.QST_admin_label' => 'website' ) , 'order' => 'DESC' ) );
        if( $company_answer ){
            $is_contact_data[ 'Company' ] = $company_answer->pretty_value();
        }

        //get the last answer this attendee provided to the question wtih admin label 'company'
        $company_answer = EEM_Answer::instance()->get_one( array( array( 'Registration.ATT_ID' => $ee_attendee->ID(), 'Question.QST_admin_label' => 'custom_question' ) , 'order' => 'DESC' ) );
        if( $company_answer ){
            $is_contact_data[ '_Company' ] = $company_answer->pretty_value();
        }
    }else{
        EE_Error::add_error(sprintf( __( 'ee_infusionsoft_save_my_custom_questions was not called with an EE_Attendee but a %s', 'event_espresso' ), gettype( $ee_attendee )), __FILE__, __FUNCTION__, __LINE__ );
    }
    return $is_contact_data;
}
add_filter( 'FHEE__EED_Infusionsoft__save_infusionsoft_attendee__extra_attendee_data', 'ee_infusionsoft_save_my_custom_questions', 10, 2 );

/* Stop Adding Functions */

Thanks, Mike

  • This topic was modified 6 years, 7 months ago by  Tony. Reason: Code formatting


Josh

  • Support Staff

September 25, 2017 at 8:59 am

Hi Mike,

There are actually examples for two different fields in the code example, hence the repetition. Here’s a link to some sample code that shows only one field, and includes more inline instruction about what to change:

https://gist.github.com/joshfeck/07d2c6598f33043b67e5b9f4f8645f3b


Mike Doughty

September 25, 2017 at 11:33 pm

Hi,

I’ve followed the directions in the new code and tested and still the company field is not being pulled through into Infusionsoft.

The code is as follows, and the instructions require to change only two items, which I’ve done.

Can you please let me know what is incorrect in the code, as it should work based on the code provided.

“//* Please do NOT include the opening php tag, except of course if you’re starting with a blank file
function ee_infusionsoft_save_my_custom_questions( $is_contact_data, $ee_attendee ) {
if( $ee_attendee instanceof EE_Attendee ) {
//get the last answer this attendee provided to the question with admin label ‘custom_question’
$custom_question_answer = EEM_Answer::instance()->get_one(
array(
array(
‘Registration.ATT_ID’ => $ee_attendee->ID(),
// change custom_question on the next line to match the admin label in EE > Registration Forms > Questions
‘Question.QST_admin_label’ => ‘Company’
),
‘order’ => ‘DESC’
)
);
if( $custom_question_answer ){
// change _CustomQuestion on the next line to match the Infusionsoft custom field
$is_contact_data[ ‘_Company’ ] = $custom_question_answer->pretty_value();
}
}else{
EE_Error::add_error(
sprintf(
__(
‘ee_infusionsoft_save_my_custom_questions was not called with an EE_Attendee but a %s’, ‘event_espresso’
), gettype( $ee_attendee )
),
__FILE__, __FUNCTION__, __LINE__
);
}
return $is_contact_data;
}
add_filter(
‘FHEE__EED_Infusionsoft__save_infusionsoft_attendee__extra_attendee_data’,
‘ee_infusionsoft_save_my_custom_questions’,
10,
2
);

/* Stop Adding Functions */


Josh

  • Support Staff

September 26, 2017 at 10:37 am

Hi Mike,

Before we try determine whether your code is correct or not, let’s first make sure it’s loading and executing at the right moment. If the code loads too late that will just not do. May I ask is the code within a theme’s functions.php file or is it within a custom functions plugin. If the latter, is the plugin set to Activated on the WP > Plugins page?


Mike Doughty

September 26, 2017 at 5:01 pm

Hi,

I have this in my own custom plugin, which is active in my list of plugins for the site.

Here is an event page, where I have a 0 dollar event setup, that you can test. This should be sending through the company details to Infusionsoft.

http://events.getbusiness.fit/?espresso_events=getting-better-clients-quicker

Happy to give you access to the site if you need to check that way. Just really need to get this sorted so I can start marketing the event.

Thanks, Mike


Josh

  • Support Staff

September 26, 2017 at 5:19 pm

Testing the registrations isn’t going to help me find if there’s anything in the code that needs to be adjusted. The two items that we need to verify are
1) the admin question label for the “Company” question. Here’s a screenshot of that field, outlined in green, from a similar question from my site:
https://www.evernote.com/l/AAT_28P0cfdEqYYIb0-WfpNOAeN7CLqqgZI
So you might have something like company input for that field.
That’s the value that gets plugged into line 13 of the code example:
https://gist.github.com/joshfeck/07d2c6598f33043b67e5b9f4f8645f3b#file-ee_infusionsoft_custom_field_example-php-L13

2) The field from Infusionsoft’s end. Are you certain you should be trying to pass the company name to a custom field? There’s a standard field for that and you’re likely going to map to the standard field, so your line 20 from the code will be
$is_contact_data[ 'Company' ] = $custom_question_answer->pretty_value();


Mike Doughty

September 26, 2017 at 5:39 pm

Hi,

The custom question label in EE is “company”, which is what I have in my code, as per the instructions.

With item two you can see that what you have in your code is exactly the same as my code, so not sure why you are asking that.

My line 20
$is_contact_data[ ‘_Company’ ] = $custom_question_answer->pretty_value();

your line 20
$is_contact_data[ ‘Company’ ] = $custom_question_answer->pretty_value();

Please advise what the issue is, as I can’t see anything that is wrong.

Thanks, Mike


Tony

  • Support Staff

September 27, 2017 at 1:46 am

The custom question label in EE is “company”, which is what I have in my code, as per the instructions.

In your code you have: ‘Question.QST_admin_label’ => ‘Company’

‘Company’ and ‘company’ are not the same, your code uses ‘Company’, so is your question label capitalized? If not change your code to match it exactly.


Mike Doughty

September 27, 2017 at 2:34 am

Hi,

Ok, so I checked and the admin label in EE is ‘company” with a small “c”, and so I changed the code in my plugin to now be

“// change custom_question on the next line to match the admin label in EE > Registration Forms > Questions
‘Question.QST_admin_label’ => ‘company’ ”

I tested and still not coming through.

What is next to test to make this happen?

Thanks, Mike


Tony

  • Support Staff

September 27, 2017 at 4:47 am

Ok, in IS what did you add the custom field to? Contact?

Any custom field from InfusionSoft needs to be prefixed with an underscore and you need to use the database name for the field which may not be the same as the field name, for example take a look here – http://take.ms/qeBtHt

That’s the custom fields for Contacts on my account, note that ‘Company’ is listed there, but if I click the ‘View the field database names (for the API)’ link on that page I see – http://take.ms/0JysB

Meaning for that field I need to use $is_contact_data[ '_Company0' ] so confirm your database field name.

Also when testing are you testing new contacts or existing contacts?


Josh

  • Support Staff

September 27, 2017 at 6:40 am

Hi Mike,

With item two you can see that what you have in your code is exactly the same as my code, so not sure why you are asking that.

It’s not exactly the same Mike. Do you see that one has an underscore and the other doesn’t. This is a difference and it’s an important one. Are you using a custom field for company in IS or a standard field? This is an important distinction.

If it’s a standard field, you don’t use an underscore:
$is_contact_data[ 'Company' ] = $custom_question_answer->pretty_value();

If it’s a custom field you do use an underscore:

$is_contact_data[ '_Company' ] = $custom_question_answer->pretty_value();


Mike Doughty

September 27, 2017 at 3:07 pm

Hi Josh,

Thanks, I took out the underscore and it seems to be working, wahoo!!

If I want to push through another standard field in Infusionsoft, like Job Title, is it just a matter of copy the code, and inserting it at the end, ie before the else statement, or when you are pushing through multiple custom questions is the code different?

“//get the last answer this attendee provided to the question with admin label ‘custom_question’
$custom_question_answer = EEM_Answer::instance()->get_one(
array(
array(
‘Registration.ATT_ID’ => $ee_attendee->ID(),
// change custom_question on the next line to match the admin label in EE > Registration Forms > Questions
‘Question.QST_admin_label’ => ‘company’
),
‘order’ => ‘DESC’
)
);
if( $custom_question_answer ){
// change _CustomQuestion on the next line to match the Infusionsoft custom field
$is_contact_data[ ‘Company’ ] = $custom_question_answer->pretty_value();
}”

Thanks, Mike


Josh

  • Support Staff

September 27, 2017 at 3:30 pm

The code you add will be slightly different because you’ll need to make sure you add unique variables that push new unique keys to the array of data that’s sent to IS. The example code in the documentation actually has two fields being passed to infusionsoft (the first one is a standard field, the second one is a custom field). You can send two standard fields in the same manner though.

https://eventespresso.com/wiki/infusionsoft-integration/#ee4-saving-registration-questions-as-standard-or-custom-fields

The support post ‘Mapping Custom Questions to Infusionsoft’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso