Adding data to WixCrm, WixUser and someDataCollection at one button click operation.

Hi, I am trying to create member. I have created a member database “Agent”, which holds all the relevant info for the member. When the user is being registered to the site, they will fill up a form


Once the form is filled up, they will click on the button “Submit”, and I have written the below code for it

import wixUsers from ‘wix-users’;
import wixCRM from ‘wix-crm’;
import wixData from ‘wix-data’;

//Global variables for string concatination operations
var FirstName;
var LastName;

var strUnit = “”;
var strStNumber = “”;
var strStName = “”;
var strSuburb = “”;
var strPostCode = “”;
var strState = “”;
var fullAddress = “”;

var slash = ‘/’;
var space = " ";
var comma =‘,’;
var hyphen = ‘-’;
let uba;
let ubp;
$w.onReady( function () {

});

export function btnSubmitAgent_click(event) {
//Add your code for this event here:

$w(" #ubAgentLicense").startUpload()
.then( (uploadedFile) => {
return uba = uploadedFile.url;
})
. catch ( (err) => {
let errorMsg = err;
console.log(errorMsg);
} );
$w(" #ubAgentPic").startUpload()
.then( (uploadedFile) => {
return ubp = uploadedFile.url;
})
. catch ( (err) => {
let errorMsg = err;
console.log(errorMsg);
} );
let email = $w(‘#iEmail’).value;// the user’s email addresses
let password = $w(‘#iPassword’).value;// the user’s password
let firstName = $w(‘#txtFirstName’).value; // get first name
let lastName = $w(‘#txtLastName’).value;// get last name
let phone = $w(‘#iMobile’).value;// get phone number
let address = $w(‘#iFullAddress’).value;
let membertype = ‘Agent’;
let agentLicenseNumber = $w(‘#txtAgentLicense’).value;
let agentFullName = $w(‘#txtFullName’).value;
let agentExperienceYears= $w(‘#ddExperience’).value;
let isAgentLicenseValid = $w(‘#chkLicenseValidity’).value; // get first name,
let agentLicense = uba;
let agentPicture = ubp;
let agentBio = $w(‘#rtbAgentBio’).value;
let driverLicenseNumber = $w(‘#txtDriverLicense’).value;
let mobile= $w(‘#iMobile’).value;
let workPhone = $w(‘#iWrkPhn’).value;
let homePhone = $w(‘#iHmPhn’).value;
let unitNumber = $w(‘#txtUnitNumber’).value;
let streetNumber = $w(‘#txtStreetNumber’).value;
let suburb = $w(‘#txtSuburb’).value;
let state = $w(‘#ddState’).value;
let postCode = $w(‘#txtPostCode’).value;
let streetName = $w(‘#txtStreetName’).value;

// create member
wixUsers.register(email, password)
.then( (result) => {
let status = result.status; // “Active”
let user = result.user;
} )
. catch ( (err) => {
let errorMsg = err;
console.log(errorMsg);
} );
// create CRM data
wixCRM.createContact( {
“firstName”: firstName,
“lastName”: lastName,
“emails”: [email],
“phones”: [phone],
“address”: address,
“memberType”: membertype
} )
. catch ( (err) => {
let errorMsg = err;
console.log(errorMsg);
} );

let toInsert = {
“agentLicenseNumber”: agentLicenseNumber,
“agentFirstName”: firstName,
“agentLastName”: lastName,
“agentFullName”: agentFullName,
“agentExperienceYears”: agentExperienceYears,
“isAgentLicenseValid”: isAgentLicenseValid,
“agentLicense”: uba,
“agentPicture”: ubp,
“agentBio”: agentBio,
“driverLicenseNumber”: driverLicenseNumber,
“email”: email,
“mobile”:mobile,
“workPhone”: workPhone,
“homePhone”: homePhone,
“unitNumber”:unitNumber,
“streetNumber”:streetNumber,
“suburb”: suburb,
“state”: state,
“postCode”: postCode,
“fullAddress”:fullAddress,
“streetName”: streetName
};

wixData.insert(“Agent”, toInsert)
.then( (results) => {
let item = results; //see item below
} )
. catch ( (err) => {
let errorMsg = err;
console.log(errorMsg);
} );
}

I am getting the following errors


Loading the code for the Recruit Agent page. To debug this code, open dd417.js in Developer Tools.

unknown failure (404)

Illegal signature - missing dot separator [wixcode-dev.f5ae4288a17b8e4e67d174d12e24e08c489f654d.eyJpbnN0YW5jZUlkIjoiMGI5ZjM5ZTctMzI1ZC00MWI4LThkMWUtYjBlNzM4YWZmMGJlIiwiY29ycmVsYXRpb25JZCI6IjgzYWUzZTBlLTI5MDMtNDI1NS04NDUxLWViNTIxOGNmYmFmYSIsInNlc3Npb25VSWQiOiJjMmQ5NmNhZi02Yzk2LTRjMDgtYmI2Ny03MDM2ZGI5ZGIwODMiLCJpc1RlbXBsYXRlIjpmYWxzZSwic2lnbkRhdGUiOjE1NDY0NDQ3NTM3OTksInNpdGVNZW1iZXJJZCI6ImMyZDk2Y2FmLTZjOTYtNGMwOC1iYjY3LTcwMzZkYjlkYjA4MyIsInVpZCI6ImMyZDk2Y2FmLTZjOTYtNGMwOC1iYjY3LTcwMzZkYjlkYjA4MyIsImFwcERlZklkIjoiQ2xvdWRTaXRlRXh0ZW5zaW9uIiwiaXNBZG1pbiI6ZmFsc2UsIm1ldGFTaXRlSWQiOiJlY2VhM2Y0Yi1iMGUxLTQ3ZjQtODg4NC00NTlkMjE2NTcwODEifQ==] (500)

TypeError: Cannot read property ‘charAt’ of undefined


I need to input data into 3 different databases at the same time BUT if any ONE of them fails, then NONE should success. I need some help to solve the problems. thank you

Hi is there anyone who can HELP me solving the issues. I should also add one more thing. I actually need to set the role of the user when they register by code. The approval process will be automatic and when the user registers based on their “member type” selection from the member drop down box (which i will add), I need them to give the roles like, Buyer, Seller, Agent etc. I have already created the “member type” field in the CRM and also all the roles .

Please help me to solve the issue. It will be a great favor. Thank you.

Is there NO ONE who can help !!!

I am still hoping someone from the wix team WILL HELP ME…

Hi,
The code looks good and should work, but it looks like you are testing the API from the editor preview. We are aware of an issue with this API in preview and working on a fix for that matter.
Can you please try to test the API in the live site, it should work there.