netsuitesuitecommerce

Access Customer Table from within SCA SuiteScript


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:


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

    }
});

Solution

  • What I do is create a companion .ss file and give it the permissions. Then you call it with nlapiRequestURL and get the data back. This is a little more convenient than a suitelet since you keep all the files together and have a simpler URL to deal with

    You would call this server side with nlapiRequestURL. Either from your SuiteScript/Account/Model.js or from services/Account.Register.Service.ss

    You could also call it client side to validate the email prior to registering. You'd disable the Register button until you've gotten a clean email assessment.