When a user registers in our SCA Mont Blanc website we need to check that their email is unique before creating a user. So we have editted the Accounts@1.X.X/SuiteScript/Account.Model.js
file to check the Customer
table for any users with a specific email address prior to registering a new user.
The problem is: that script executes under the role Customer Center
and it doesn't have permission to view/query the Customer
table. So our check crashes the script.
How can we access the Customer
table upon user registration (specifically the file Accounts@1.X.X/SuiteScript/Account.Model.js
)? Is there any solution/advice you can provide as I am quite stuck :(
The things I have tried:
- Change the role/permissions of the service file
services/Account.Register.Service.ss
to execute under a new role I created calledWebstore User
. Unfortunately that caused the login page to show an error;You do not have permission to view this page
. Maybe I didn't change the right file or setup the new role correctly? - Created a new role that had all permissions of
Customer Centre
plusview
permission forCustomers
. But same error as above.
AccountOverrides@1.0.0/SuiteScript/Account.Model.js
...
return SCModel.extend({
name: 'Account'
, register: function (user_data)
{
// Check if there is already a user/customer with this email address
// The below function will crash the script because
// the script cannot access the 'customer' table
var emailDulicates = nlapiSearchRecord('customer', null,
new nlobjSearchFilter('email', null, 'is', ''+user_data.email));
if (emailDulicates && emailDulicates.length > 0) {
Application.sendError({"Email already taken."});
return false;
}
... continue on to register user
}
});