Hey guys! Hope you have been good so far, given our current situation global-wise…
I’m currently setting up a custom form with each separate entry elements to my website using input values as well as dropdown values. My main intention by doing so is to be able to create brand new contacts after the user clicks the ‘submit’ button, so that these contacts can later be used in my email marketing sendings.
The problem, however, lies in the fact that, for some odd reason, when using the createContact() function from Wix-CRM, it simply does not add any of the custom fields I’ve set up at all. I mean, no matter what changes I implement in my code, it simply won’t accept these saved values when creating the new contact.
I’ve followed LITERALLY the exact same code lines from this tutorial in Wix Support Article: https://support.wix.com/en/article/velo-tutorial-sending-a-triggered-email-to-contacts
Yet it still won’t work whatsoever. I just want to be able to add the user selected dropdown option value to a custom field called “interestAreas”, as well as to Wix default field for “Company”.
Albeit the fact I’ve also been following the same steps regarding contactInfo creation and matching key:values for my new custom field, as stated in https://www.wix.com/velo/reference/wix-crm/createcontact , the thing is, for some odd damn reason, the Wix JS code won’t save these fields at all, no matter what. It can save firstName and email based on the user inputs, but it still won’t save neither the company nor the interestArea field I’ve created.
You can see a bit of my coding as well as how things are set up based on these screenshots and snippets as follows:
Setting up conditional dropdown enable/disable options (this one has gotten no problems at all, this is just to let you know the full code behind it)
import wixData from 'wix-data';
import wixCrm from 'wix-crm';
$w.onReady(function () {
});
export function dropdown1_change(event, $w) {
if ($w('#dropdown1').value === 'USP' || $w('#dropdown1').value === 'FGV') {
$w('#dropdown2').enable();
instituicao2Filter();
}
else if ($w('#dropdown1').value !== 'USP' || $w('#dropdown1').value !== 'FGV' || $w('#dropdown1').value !== 'Outros') {
$w('#dropdown2').disable();
$w('#dataset2').setFilter( wixData.filter() );
$w('#dropdown2').selectedIndex = undefined;
$w('#dropdown2').resetValidityIndication();
$w('#input3').value = undefined;
$w('#input3').resetValidityIndication();
}
if ($w('#dropdown1').value === 'Outros') {
$w('#input3').enable();
}
else if ($w('#dropdown1').value !== 'Outros') {
$w('#input3').disable();
$w('#input3').value = undefined;
$w('#input3').resetValidityIndication();
}
}
function instituicao2Filter () {
$w('#dataset2').setFilter( wixData.filter().contains('instituicao1A', $w('#dropdown1').value ));
}
Setting up conditional create contact code (this one doesn’t work whatsoever for the Company or interestAreas fields)
export function button6_click(event, $w) {
let firstName = $w('#input1').value;
let email_add = $w('#input2').value;
let instituicaoA = $w('#dropdown1').value;
let instituicaoB = $w('#dropdown2').value;
let instituicaoC = $w('#input3').value;
let contactInfo1 = {
'firstName': firstName,
'emails': [email_add],
'Company': instituicaoA,
'interestAreas': instituicaoA
};
let contactInfo2 = {
'firstName': firstName,
'emails': [email_add],
'Company': instituicaoB,
'interestAreas': instituicaoB
}
let contactInfo3 = {
'firstName': firstName,
'emails': [email_add],
'Company': instituicaoC,
'interestAreas': instituicaoC
}
if (instituicaoA === 'USP' || instituicaoA === 'FGV') {
wixCrm.createContact(contactInfo2)
.then((contactId) => {
return wixCrm.emailContact('mailing_inscrito', contactId);
});
}
if (instituicaoA !== 'USP' || instituicaoA !== 'FGV' || instituicaoA !== 'Outros') {
wixCrm.createContact(contactInfo1)
.then((contactId) => {
return wixCrm.emailContact('mailing_inscrito', contactId)
});
}
if (instituicaoA === 'Outros') {
wixCrm.createContact(contactInfo3)
.then((contactId) => {
return wixCrm.emailContact('mailing_inscrito', contactId)
});
}
}
I even have found some posts here in the forum regarding this custom field issue, such as this one right here => https://www.wix.com/velo/forum/community-discussion/wix-crm-in-wix-code-not-saving-in-custom-fields
Notwithstanding, there seems to be no conclusive solution for this often error when creating a new contact using code. I can send the triggered email just fine using the aforementioned code, based on the new created contactId from firstName and emails fields, yet neither Company nor interestAreas seem to work when assigning to the contact field.
I don’t know if it’s worth mentioning, but the submit button event saves the contact infos just fine to my #dataset3 , but I’ve set it up using Wix UI Connect to Data button, not thru code. Therefore, although I tested using this onAfterSave() function, that time the contact wasn’t even created at all, so I assumed my case for this form submission and dataset assigning didn’t have anything to do with this createContact() issue.
Thus, I’d highly appreciate if you guys could address my issue, in order that we might reach a resolution for this nerve-racking circumstance.
P.S.: sorry for the different language in the screenshot, that’s actually Portuguese, but feel free to ask me for any translations. Also, if anyone feels comfortable by joining me in a Zoom call, I’m free to do it, so we can try and solve this thing in a more assertive means. And I’m completely new to coding as well, never have I ever written a single piece in JavaScript not before this week; the only past record I had was with Python for a college project, so please pardon me for the newbie ignorance here.