0

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 called Webstore 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 plus view permission for Customers. 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

    }
});
sazr
  • 24,984
  • 66
  • 194
  • 362

1 Answers1

1

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.

bknights
  • 14,408
  • 2
  • 18
  • 31
  • thanks very much for the advice :) I will give it a go. When you say call `nlapiRequestURL()` I assume you mean I call this server side (inside my `SuiteScript/Account.Model.js`)? Or I call this client side like a regular service (ie, in my backbone view or model)? – sazr Apr 25 '17 at 05:52
  • in your experience of SCA have you come across the session bugs I describe [here](http://stackoverflow.com/questions/43600707/sca-webstore-session-bugs)? Is it an SCA thing? If not I've got some bugs in my new/overridden modules. – sazr Apr 25 '17 at 05:54