“Customer Notification” tab navigate to a new page in the my accounts section and save the form values in Netsuite in the created custom record using extension.

Javacsript Entry file


define(
	'JJ.MyaccountNav.MyaccountNav'
,   [
		'JJ.MyaccountNav.MyaccountNav.View'
		,'JJ.MyaccountNav.MyaccountNav.Router'
	]
,   function (
		MyaccountNavView
		,myaccountnavrouter
	)
{
	'use strict';

	return  {
		mountToApp: function mountToApp (container)
		{
			var myaccountmenu = container.getComponent('MyAccountMenu');
			var customernotificationGroupEntry = {
				id: "customer_notification"
				, name: "Customer Notification"
				, index: 6
				, url: "update-terms-and-conditions"
				,permissionoperator: "OR"
				,permission: [
			         {
			             group: "transactions",
			             id: "tranSalesOrd",
			             level: "1"
			         },
			         {
			             group: "transactions",
			             id: "tranEstimate",
			             level: "1"
			         }
			     ]
			}
			myaccountmenu.addGroup(customernotificationGroupEntry);
			return new myaccountnavrouter(container);
	

		}
	};
});

Router File

define('JJ.MyaccountNav.MyaccountNav.Router'
, [
    'Backbone'
  , 'JJ.MyaccountNav.MyaccountNav.View'
  ]
, function
  (
    Backbone
  , MyaccountNavView
  )
{
  'use strict';

  return Backbone.Router.extend({
    routes:
    {
       'update-terms-and-conditions': 'termsView'
    }

  , initialize: function (container)
    {
      this.application = container;
      this.UserProfile = container.getComponent('UserProfile');
    }

  ,termsView: function ()
    {
      var self = this;
      this.UserProfile.getUserProfile().then(function (profileData)
      {
        var view = new MyaccountNavView
        ({
          application: self.application
        , UserProfile: profileData
        })

        view.showContent();
      });
    }
  })
});

View File

// @module JJ.MyaccountNav.MyaccountNav
define('JJ.MyaccountNav.MyaccountNav.View'
,	[
	'jj_myaccountnav_myaccountnav.tpl'
	,'JJ.MyaccountNav.MyaccountNav.Model'
	
	//,	'JJ.MyaccountNav.MyaccountNav.SS2Model'
	
	,	'Backbone'
    ]
, function (
	jj_myaccountnav_myaccountnav_tpl
	,JJMyaccountNavMyaccountNavModel
	
	//,	MyaccountNavSS2Model
	
	,	Backbone
)
{
    'use strict';

	// @class JJ.MyaccountNav.MyaccountNav.View @extends Backbone.View
	return Backbone.View.extend({

		template: jj_myaccountnav_myaccountnav_tpl

	,	initialize: function (options) {

			
		}

	,	events: {
		//'click [data-action="submit-form"]': 'customSaveForm'
		"submit #Get-In-Touch": 'customSaveForm'
		}

	,	bindings: {
		'[name="name"]': 'name',
		'[name="date"]': 'date',
		'[name="email"]': 'email',
		'[name="phone"]': 'phone',
		'[name="comments"]': 'comments'
		}

	, 	childViews: {

		}


		//@method getContext @return JJ.MyaccountNav.MyaccountNav.View.Context
	,
	    customSaveForm: function(e) {
			var self = this;
			var values = {};
			e && e.preventDefault();
			jQuery("form .global-views-message").parent().remove();
			$.each($("#Get-In-Touch").serializeArray(), function (i, field) {
				values[field.name] = field.value
			});

			var name = values["name"];
			var date = values["date"];
			var email = values["email"];
			var phone = values["phone"];
			var comments= values["comments"];
			console.log("name from customer notification form is",name)
			console.log("date from customer notification form is",date)
			console.log("email from customer notification form is",email)
			console.log("phonenumber from customer notification form is",phone)
			console.log("comment from customer notification form is",comments)
			
			var model=new JJMyaccountNavMyaccountNavModel();

			    model.fetch({ data: { name: name, date: date, email: email, phone: phone, comments: comments } }).done(function () {
                     console.log('model8989', model);
                    //promise.resolve();
                });
		}




	,	getContext: function getContext()
		{
			//@class JJ.MyaccountNav.MyaccountNav.View.Context
			this.message = this.message || 'Hello World!!'
			return {
				message: this.message
			};
		}
	});
});

Suite Script JJ.MyaccountNav.MyaccountNav.js file

// JJ.MyaccountNav.MyaccountNav.js
// Load all your starter dependencies in backend for your extension here
// ----------------

define('JJ.MyaccountNav.MyaccountNav'
,	[
		'JJ.MyaccountNav.MyaccountNav.ServiceController',
		'SC.Model','SC.Models.Init', 'Application', 'Utils', 'Backbone.Validation','underscore'
	]
,	function (
		MyaccountNavServiceController,SCModel,ModelsInit, Application, Utils,BackboneValidation, _
	)
{
	'use strict';
	return SCModel.extend({
		name: 'GetInTouch'
		,
		CreateLead: function (data) {
			console.log('name inside createlead', data);
		try {
			
			/*var profile = ProfileModel.get();
				console.error('profileseet', profile)
             var customer = nlapiGetUser();
              console.error('customer123', customer);*/
              var customerRecord = nlapiCreateRecord('lead');
			  if (data.name) {
			  	firstname = Utils.sanitizeString(data.name);
			  	customerRecord.setFieldValue('firstname', firstname);
			  }
			  if (data.name) {
			  	lastname =  Utils.sanitizeString(data.name);
			  	customerRecord.setFieldValue('lastname', lastname);
			  }
			  if (data.name) {
			  	firstname = Utils.sanitizeString(data.name);
			  	customerRecord.setFieldValue('custentity_name_cust', firstname);
			  }
			  if (data.date) {
			  	date = Utils.sanitizeString(data.date);
			  	customerRecord.setFieldValue('custentity_date_cust', date);
			  }
			  if (data.email) {
			  	email = Utils.sanitizeString(data.email);
			  	customerRecord.setFieldValue('custentity_email_cust', email);
			  }
			  if (data.phone) {
			  	phone = Utils.sanitizeString(data.phone);
			  	customerRecord.setFieldValue('custentity_phone_cust', phone);
			  }
			  if (data.comments) {
			  	comments = Utils.sanitizeString(data.comments);
			  	customerRecord.setFieldValue('custentity_comments_cust', comments);
			  }
			  nlapiSubmitRecord(customerRecord);
			  return {
			  	successMessage: 'Your request has been submitted'
			  }
			} catch (e) {
			// statements
			console.error('err@contactus', e);
			return {
				status: 500,
				code: 'ERR_FORM',
				message: 'There was an error submitting the form, please try again later'
			}
		  }
		}
    });
});



Service Controller file

define("JJ.MyaccountNav.MyaccountNav.ServiceController"
  , ['ServiceController','Application','JJ.MyaccountNav.MyaccountNav'

  ]
  , function(
  ServiceController,Application,MyaccountNav
) {
  "use strict";

  return ServiceController.extend({
    name: "JJ.MyaccountNav.MyaccountNav.ServiceController",

    // The values in this object are the validation needed for the current service.
    options: {
      common: {}
    },

    get: function get() {
     
       console.log("Test Service controller get")

       var name = this.request.getParameter('name');
       var date = this.request.getParameter('date');
       var email = this.request.getParameter('email');
       var phone = this.request.getParameter('phone');
       var comments = this.request.getParameter('comments');
      console.log("name from customer notification form is",name)
      console.log("date from customer notification form is",date)
      console.log("email from customer notification form is",email)
      console.log("phonenumber from customer notification form is",phone)
      console.log("comment from customer notification form is",comments)

      return MyaccountNav.CreateLead({
        name: name,
        date: date,
        email: email,
        phone: phone,
        comments: comments
      });
   
    

    },

    post: function post() {
      // not implemented
    },

    put: function put() {
      // not implemented
    },

    delete: function() {
      // not implemented
    }
  });
});

Change in manifest file entri point as service controller

  "ssp-libraries": {
        "entry_point": "Modules/MyaccountNav/SuiteScript/MyaccountNav.ServiceController.js",
        "files": [
            "Modules/MyaccountNav/SuiteScript/JJ.MyaccountNav.MyaccountNav.js",
            "Modules/MyaccountNav/SuiteScript/MyaccountNav.ServiceController.js"
        ]
    },

Create a custom record in the NetSuite with fields below
Name
Comments
Date of birth
Phone number
Email

Go to Customization > Lists, Records, & Fields > Entity Fields.

Leave a comment

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