Jira Code: VG-88
The field id “phone” in the contact record of the customer is updated with the phone field value entered during customer registration.
Suitescript
Account.Model.js : register method in Account.Model.js
register: function (user_data)
{
//var customer = ModelsInit.getCustomer();
if (ModelsInit.customer.isGuest())
{
var guest_data = ModelsInit.customer.getFieldValues();
ModelsInit.customer.setLoginCredentials({
internalid: guest_data.internalid
, email: user_data.email
, password: user_data.password
});
ModelsInit.session.login({
email: user_data.email
, password: user_data.password
});
ModelsInit.customer.updateProfile({
internalid: guest_data.internalid
, firstname: user_data.firstname
, lastname: user_data.lastname
, companyname: user_data.company
, emailsubscribe: (user_data.emailsubscribe && user_data.emailsubscribe !== 'F') ? 'T' : 'F'
});
}
else
{
user_data.emailsubscribe = (user_data.emailsubscribe && user_data.emailsubscribe !== 'F') ? 'T' : 'F';
ModelsInit.session.registerCustomer({
firstname: user_data.firstname
, lastname: user_data.lastname
, companyname: user_data.company
, email:user_data.email
, password:user_data.password
, password2:user_data.password2
, emailsubscribe: (user_data.emailsubscribe && user_data.emailsubscribe !== 'F') ? 'T' : 'F'
});
//updating the customer record with the custom fields in registration form
customer.updateProfile({
internalid: user_data.customerid,
customfields: {
"custentity_company_website":user_data.company_website,
"custentity_accesscontrol":user_data.access_control,
"custentity_audio_survelliance":user_data.audio_surveillance,
"custentity_home_automation":user_data.home_automation,
"custentity_video_survelliance":user_data.video_survelliance,
"custentity_other":user_data.other_field
}
});
//adding address to the customer
customer.addAddress({
internalid: user_data.customerid,
addressee : user_data.firstname,
addr1 : user_data.Address_1,
city : user_data.city,
state : user_data.state,
zip : user_data.zip,
country : user_data.country,
phone : user_data.phone,
defaultshipping : 'T',
defaultbilling : 'T'
});
//updating the contact record of the customer, created during the customer registration with the phone-no.
//The field id "phone" in the contact record is updated with the phone field value entered during customer registration.
var customerid = customer.getFieldValues(['internalid']).internalid;
var contactSearch = nlapiSearchRecord("contact",null,
[
["customer.internalidnumber","equalto",customerid]
],
[
new nlobjSearchColumn("internalid")
]
);
var internalid = contactSearch[0].getValue("internalid") || undefined;
var record = nlapiLoadRecord('contact', internalid, {
recordmode : 'dynamic'
});
record.setFieldValue('phone',user_data.phone);
nlapiSubmitRecord(record);
}
//checking whether the customer is approved.
//Only if the checkbox LOGIN ACCESS(fieldid:custentity_loginaccess) in the customer record is checked, can a customer login to the website.
var loginAccess;
var customFields = nlapiGetWebContainer().getShoppingSession().getCustomer().getCustomFieldValues();
var pVar2 = JSON.stringify(customFields, null, 2);
var pVar3Arrray = JSON.parse(pVar2);
for (var i = 0; i < pVar3Arrray.length; i++) {
loginAccess = pVar3Arrray[8].value;
}
if(loginAccess == "T"){
console.log('Login Access checked');
var user = Profile.get();
user.isLoggedIn = ModelsInit.session.isLoggedIn2() ? 'T' : 'F';
user.isRecognized = ModelsInit.session.isRecognized() ? 'T' : 'F';
return {
touchpoints: ModelsInit.session.getSiteSettings(['touchpoints']).touchpoints
, user: user
, cart: LiveOrder.get()
, address: Address.list()
, creditcard: CreditCard.list()
};
}
else
{
session.logout();
throw new Error('Your application will be reviewed and a member of our dealer team will contact you within 1-2 business days.');
}
}