when we are using multiple domines in single NetSuite how to show restrict message for the same email and password customer from other domines.

Using this suitlet we can show the error message by default when in the US subsidiary using same email and password of AU or NZ while login from US subsidiary it will login or show the successful message.

 //getting the values of email and subsidiary
            var customParms = '&email=' + user_data.email + '&subsidiary=' + user_data.subsidiary_value;
            //In the response getting the suitlet values of exesting email in the subsidery
            var response = nlapiRequestURL('https://5742647.extforms.netsuite.com/app/site/hosting/scriptlet.nl?script=1002&deploy=1&compid=5742647&h=75d7c8ca2ca7d07f9b7e' + customParms, null, null, 'GET');
            if (response.body !== '') {
                bodyObject = JSON.parse(response.body)
            } else {
                bodyObject = { success: false };
            }
            var totalCustomersBefore = parseInt(bodyObject.totalCustomers);
            console.error(' bodyObjectbodyObjectbodyObject', totalCustomersBefore)
                //Showing the error message if the email is allredy exist in the subsidery
            if (totalCustomersBefore !== 0) {
                var user = Profile.get();
                var profileinfo = Profile.get();
                console.error('profileinfo', JSON.stringify(profileinfo));
                user.isLoggedIn = 'F';
                user.isRecognized = 'F';
                ModelsInit.session.logout();
                throw (nlapiCreateError("", "Error: You already have an account, Please login to checkout.", false));
            }
var responseInAllAfter = nlapiRequestURL('https://5742647.extforms.netsuite.com/app/site/hosting/scriptlet.nl?script=1002&deploy=1&compid=5742647&h=75d7c8ca2ca7d07f9b7e' + customParms1, null, null, 'GET');
                    if (responseInAllAfter.body !== '') {
                        bodyObject2 = JSON.parse(responseInAllAfter.body)
                    }
                    var responseInAllAftercust = parseInt(bodyObject2.totalCustomers);
                    console.error("responseInAllAftercust", responseInAllAftercust);
                    if (responseInAllAftercust == totalCustomersBeforeCreate) {
                        // checking same passworrd and email frow comparing 2 subsiderys to show the another domine regine link
                        if (sub1 === responseInAllAftercust) {
                            var customParmscompare1 = '&email=' + user_data.email + '&subsidiary=' + '[ 7, 1]';
                            var responseInAll = nlapiRequestURL('https://5742647.extforms.netsuite.com/app/site/hosting/scriptlet.nl?script=1002&deploy=1&compid=5742647&h=75d7c8ca2ca7d07f9b7e' + customParmscompare1, null, null, 'GET');
                            if (responseInAll.body !== '') {
                                bodyObject1 = JSON.parse(responseInAll.body)
                            }
                            var totalCustomersBeforeCreate = parseInt(bodyObject1.totalCustomers);
                            console.error("totalCustomersBeforeCreate", totalCustomersBeforeCreate);
                            console.error('responseInAll', responseInAll)

                        } else if (sub4 === responseInAllAftercust) {

                            var customParmscompare2 = '&email=' + user_data.email + '&subsidiary=' + '[ 7, 4]';
                            var responseInAll = nlapiRequestURL('https://5742647.extforms.netsuite.com/app/site/hosting/scriptlet.nl?script=1002&deploy=1&compid=5742647&h=75d7c8ca2ca7d07f9b7e' + customParmscompare2, null, null, 'GET');
                            if (responseInAll.body !== '') {
                                bodyObject1 = JSON.parse(responseInAll.body)
                            }
                            var totalCustomersBeforeCreate = parseInt(bodyObject1.totalCustomers);
                            console.error("totalCustomersBeforeCreate", totalCustomersBeforeCreate);
                            console.error('responseInAll', responseInAll)

                        } else if (sub1 + sub4 === responseInAllAftercust) {
                            var responseInAll = nlapiRequestURL('https://5742647.extforms.netsuite.com/app/site/hosting/scriptlet.nl?script=1002&deploy=1&compid=5742647&h=75d7c8ca2ca7d07f9b7e' + customParms1, null, null, 'GET');
                            if (responseInAll.body !== '') {
                                bodyObject1 = JSON.parse(responseInAll.body)
                            }
                            var totalCustomersBeforeCreate = parseInt(bodyObject1.totalCustomers);
                            console.error("totalCustomersBeforeCreate", totalCustomersBeforeCreate);
                            console.error('responseInAll', responseInAll)

                        }

                        throw ('You already have an account with same email and password in other subsidiary try with new password.')
                    } else {
                        throw ('<div class="text">You have registered successfully and you can login by your UserID and Password <div>')
                    }
used suite let code for getting the existing email in the subsidiary.
/**
 * @NApiVersion 2.x
 * @NScriptType Suitelet
 */
define(['N/search', 'N/log'], function (search, log) {
  function onRequest(context) {
    var response = context.response;
    try {
    log.error('cobn',context);
    var dataParams = context.request.parameters;
    log.error('dataParams', dataParams);
      var customerSearchObj = search.create({
        type: "customer",
        filters: [
          ["email", "is", dataParams.email],
          "AND",
          ["msesubsidiary.internalid", "anyof", dataParams.subsidiary],
          "AND",
          ["stage", "anyof", "LEAD", "PROSPECT", "CUSTOMER"]
        ],
        columns: [
          search.createColumn({
            name: "entityid",
            sort: search.Sort.ASC,
            label: "Name"
          }),
          search.createColumn({ name: "email", label: "Email" }),
          search.createColumn({ name: "phone", label: "Phone" }),
          search.createColumn({ name: "altphone", label: "Office Phone" }),
          search.createColumn({ name: "fax", label: "Fax" }),
          search.createColumn({ name: "contact", label: "Primary Contact" }),
          search.createColumn({ name: "altemail", label: "Alt. Email" })
        ]
      });
    log.error('dataParams er', customerSearchObj.runPaged().count);
if (customerSearchObj.runPaged().count > 0) {
  response.write(JSON.stringify({ success: true, message: 'Duplicate customer with the same email already exists in this subsidiary.' }));
  log.error(response)
  return response;
}
} catch (error) {
      response.write(JSON.stringify(error))
      return  response
    }
  }
  function searchExistingCustomer(request) {
    try {
      var dataParams = request.parameters;
      var customerSearchObj = search.create({
        type: "customer",
        filters: [
          ["email", "is", dataParams.email],
          "AND",
          ["msesubsidiary.internalid", "anyof", dataParams.subsidiary],
          "AND",
          ["stage", "anyof", "LEAD", "PROSPECT", "CUSTOMER"]
        ],
        columns: [
          search.createColumn({
            name: "entityid",
            sort: search.Sort.ASC,
            label: "Name"
          }),
          search.createColumn({ name: "email", label: "Email" }),
          search.createColumn({ name: "phone", label: "Phone" }),
          search.createColumn({ name: "altphone", label: "Office Phone" }),
          search.createColumn({ name: "fax", label: "Fax" }),
          search.createColumn({ name: "contact", label: "Primary Contact" }),
          search.createColumn({ name: "altemail", label: "Alt. Email" })
        ]
      });
if (customerSearchObj.runPaged().count > 0) {
  response.write(JSON.stringify({ success: true, message: 'Duplicate customer with the same email already exists in this subsidiary.' }));
  log.error(response)
  return response;
}
      var searchResult = customerSearchObj.run();
      var searchResultCount = searchResult.getRange({ start: 0, end: 1 }).length;
      var customer = [];
      searchResult.each(function (result) {
        var internalIdObj = {};
        internalIdObj.id = result.getValue({ name: 'internalid', label: 'Internal ID' });
        customer.push(internalIdObj);
        return true;
      });
      return customer;
    } catch (error) {
      log.error('ERROR', error);
      throw error;
    }
  }
  return {
    onRequest: onRequest
  };
});
used the extension customerregisterbydomine to show the error message
 //Rohit code starts
            var email = user_data.email;
            console.log("emailjr", email);
            var subsidiary = user_data.subsidiary_value;
            console.log("subsidiaryjr", subsidiary);
            var data = { 'email': 'aswathi.kunhipurayil@jobinandjismi.com', 'subsidiary': '7' }
            var url = nlapiResolveURL("SUITELET", 'customscript1002', 'customdeploy1', true);
            var customParms = '&email=' + user_data.email + '&subsidiary=' + user_data.subsidiary_value;
            var response = nlapiRequestURL('https://5742647.extforms.netsuite.com/app/site/hosting/scriptlet.nl?script=1002&deploy=1&compid=5742647&h=75d7c8ca2ca7d07f9b7e' + customParms, null, null, 'GET');
            console.log("getdate", response);
            if (response.body !== '') {
                bodyObject = JSON.parse(response.body)
            } else {
                bodyObject = { success: false };
            }
            if (bodyObject.success) {
                var user = Profile.get();
                var profileinfo = Profile.get();
                console.error('profileinfo', JSON.stringify(profileinfo));
                user.isLoggedIn = 'F';
                user.isRecognized = 'F';
                ModelsInit.session.logout();
                throw (nlapiCreateError("", "Error: You already have an account, Please login to checkout.", false));
            } 

Leave a comment

Your email address will not be published. Required fields are marked *