Help with custom registration passing data to CRM

Looking for help with a custom signup form. I am having members signup to my site where the first step passes their information (Firstname, Lastname, Email, City and State to the CRM, where they then hit a second button that submits the data to my website database, so I can store the data in both places. My problem is, I cannot get the city and state to pass to the CRM. Firstname, Lastname, email, and password work good, but no city and state. What do I need to change in the code to pass this to the contact on the CRM?

import wixUsers from ‘wix-users’;
import wixLocation from ‘wix-location’;

$w.onReady( function () {
$w(‘#register’).onClick( function () {
$w(‘#close’).show();
$w(‘#text141’).show();
let email = $w(“#email”).value
let password = $w(“#password”).value
let firstName = $w(“#firstName”).value
let lastName = $w(“#lastName”).value
let city = $w(“#city”).value
let state = $w(“#state”).value
// register as member using form data
wixUsers.register($w(‘#email’).value, $w(‘#password’).value, {
“contactInfo”: {
“firstName”: $w(‘#firstName’).value,
“lastName”: $w(‘#lastName’).value,
“city”: $w(‘#city’).value,
“state”: $w(‘#state’).value
}
});

});
});

1 Like

Hi Matthew:

CRM doesn’t have a city and state property. You need to add these as Custom fields to the contact record before you can use them in the contactInfo field of the register. Check out how to do this here:

Then per the api documentation ( ContactInfo )

Any number of custom fields. Customs fields are used to store additional information about your site’s contacts. When setting a custom field, use key:value pairs where the key matches the names defined in your site’s Contacts List . You can only set values for custom fields that already exist in the Contacts application.
Examples
Create a new contact with custom fields

import wixCRM from 'wix-crm';

// ...

let firstName = // get first name
let lastName = // get last name
let email = // get email address
let phone = // get phone number

let contactInfo = {
  "firstName": firstName,
  "lastName": lastName,
  "emails": [email],
  "phones": [phone],
  "customField1": "customValue1",
  "customField2": "customValue2"
};

wixCRM.createContact(contactInfo)
.then( (contactId) => {
  // contact created
} );

Now if you want full access to these properties then you are probably better off managing the data yourself unless this data is needed in your dashboard. The reason is that the wix-crm and wix-users APIs are not readable. You can only write to them. The only data that you have access to is the currentUser info which is an id, logged in status and email address. You will not be able to read your custom fields and will only be able to manage them by keeping duplicate copies in a data collection anyway.

So you may also want to take a look at this article:

Steve

Thanks Steve! I will give this a shot.

Answer posted 3 years ago. Any chance this access has been updated since then? Would like to be able to get a value out of a custom field to use in page code.

Hi Mike

Yes the crm and users APIs have evolved and have much more functionality. There is also direct read access to the data collections that you can access using wixData APIs.

There is also a contacts collection that you can access.