I have setup a ‘join us’ form on a website and have used the following code below to save the form details into a database and then to create a new contact and add the same custom fields into the new contact details.
The database fields are being filled in and a new contact is created, however the custom fields in the new contact is not being filled in with anything and it doesn’t send out an email in return to the new contact as per the code should do.
The fields used are as listed below as this 'Wix CRM Custom Field Name / Form Input Value:
First Name / firstName
Last Name / lastName
Email / email
Choir Role / choirRole
Read Music / readMusic
Choir Before / choirBefore
Start Now / startNow
Start Date / startDate
import wixCRM from 'wix-crm';
$w.onReady(function () {
$w("#JoinUsForm").onAfterSave( () => {
wixCRM.createContact({
"firstName": $w('#firstName').value,
"lastName": $w('#lastName').value,
"emails": [$w("#email").value],
"Choir Role": $w("#choirRole").value,
"Read Music": $w("#readMusic").value,
"Choir Before": $w("#choirBefore").value,
"Start Now": $w("#startNow").value,
"Start Date": $w("#startDate").value
})
.then((contactId) => {
wixCRM.emailContact(' joiningusform', contactId, {
"variables": {
"firstName": $w('#firstName').value,
"lastName": $w('#lastName').value,
"emails": [$w("#email").value],
"Choir Role": $w("#choirRole").value
"Read Music": $w("#readMusic").value,
"Choir Before": $w("#choirBefore").value,
"Start Now": $w("#startNow").value,
"Start Date": $w("#startDate").value,
}
})
.then(() => {
// do something after the email was sent
})
.catch((err) => {
// handle the error if the email wasn't sent
} );
}
});
});
export function registerButton_onclick(event) {
$w("#JoinUsForm").save()
}
I have viewed this Wix Code tutorial page and went through both sending a triggered email for new contacts and members wix code and it does not work even with following the guide.
Wix Code Tutorial Link
I have also looked at this Wix Code Forum post about using custom fields in contacts and it states that '- custom fields “keys” should be exactly as written in CRM app (i.e. case sensitive and with whitespaces if required). ’
Forum Post Link
Therefore my custom field in contacts of Choir Role should be Choir Role in the code and not choirRole as I would have assumed before., however after changing it to the code above, it still does not want to save anything in the custom fields.
As the code seems to not work for the sending email, I have setup two Wix Automations that trigger when the form is submitted.
One Automation is an email back to the form filler, whilst the other Automation is an email back to myself informing me that a form has been submitted.
However, on both emails the date field is shown as ‘Tue Jan 29 2019 00:00:00 GMT+0000 (Greenwich Mean Time)’, when I just want it to be displayed as ‘Tue Jan 29 2019’
If I use Wix Forms to make up the exact same form and use the select date picker from there, then the email fields are displayed correctly as ‘Tue Jan 29 2019’. But I’m not using Wix Forms and be limited to only five forms in free option or pay each month just for being able to use Automations with it and have unlimited forms when we can do exactly the same thing in Wix Code for free!
So is there a way that we can change the fields in both email replies to show just the ‘Date Only’ option?
Wix Support have already replied and stated that I can try putting the Date and Time field as text, however when doing this the date picker on the form itself will not let me link the database to that field as it is now not Date and Time!
Only way to alter it so far by their theory is to do it manually and that defeats the object of having the triggered email after the form is filled in!