Dealer application form

Need to create a dealer form to enter their details and by submitting need to create lead in netsuite

Suite script for lead creation

 var FOLDERID = 508097; //Reseller Certificates folder
                    var CONTENT = '';

                    data = JSON.parse(data);

                    console.error('In@CrateLead: Dealer', JSON.stringify(data))
                    var customerRecord = nlapiCreateRecord('lead', { recordmode: 'dynamic' });

                    //BODY FIELDS ARE POPULATED HERE
                    customerRecord.setFieldValue('entitystatus', 6); //LEAD-Unqualified 
                    var bodyFields = data.Body;

                    for (var key in bodyFields) {
                        if (key != 'image' && key != 'imageName' && key != 'imageExtn' && key != 'subscription') {
                            if (bodyFields[key] != '') {
                                customerRecord.setFieldValue(key, bodyFields[key]);
                            }
                        }
                    }

                    //SET SUBSCRIPTION
                    if (bodyFields['subscription']) {
                        customerRecord.setFieldValue('globalsubscriptionstatus', 1);
                        customerRecord.setLineItemValue('subscriptions', 'subscribed', 1, "T");
                        customerRecord.setLineItemValue('subscriptions', 'subscribed', 2, "T");
                        customerRecord.setLineItemValue('subscriptions', 'subscribed', 3, "F");
                        // customerRecord.setLineItemValue('subscriptions', 'subscribed', 4, "F");
                        // customerRecord.setLineItemValue('subscriptions', 'subscribed', 5, "F");
                    }

For sending email to admin in each lead creation

var ADMIN = 54718; //protecstyle4@gmail.com
                    var RECIPIENT = 'sales@protecstyle.com'; //'sales@iLoveblvd.com';//'ravin@jobinandjismi.com';
                    var SUBJECT = "A new Lead has been created from website";
                    CONTENT += "Lead Record ID: " + recID + "<br>";
                    CONTENT += "Company Name: " + bodyFields.companyname + "<br>";
                    CONTENT += "E-mail: " + bodyFields.email + "<br>";
                    CONTENT += "<br><hr>";
                    CONTENT += '<a href="https://1312745.app.netsuite.com/app/common/entity/custjob.nl?id=' + recID + '">Click here to go to the record</a>';

                    nlapiSendEmail(ADMIN, RECIPIENT, SUBJECT, CONTENT);

Validating different fields

var urlRegex = /(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})/gi;
            var numberRegex = /^[0-9]*$/;

            var zip = $('[name="Zip"]').val();
            var website = $('[name="Website"]').val();
            var phone = $('[name="Phone"]').val();


            if (website != '') {
                if (!urlRegex.test(website)) {
                    $('[name="Website"]').addClass('error-input');
                    swal('Info', 'Enter Valid Website URL', 'error');

                    return false;
                } else {
                    $('[name="Website"]').removeClass('error-input');

                }
            }
            if (phone != '' && phone != '___-___-____') {
                var isPhoneValid = this.validatePhone(phone);
                if (isPhoneValid) {
                    $('[name="Phone"]').removeClass('error-input');
                } else {
                    swal('Info', 'Enter Valid Phone', 'error');
                    return false;
                }
            }


            return true;

        },
        ValidateMandatoryFields: function() {
            var valid = true;
            for (var i = 0; i < this.mandatoryFields.length; i++) {
                var attribute = '[name="' + this.mandatoryFields[i] + '"]';
                if ($(attribute).val() == '') {
                    $(attribute).addClass('error-input');
                    valid = false;
                }
            }

            if (valid) {
                var email = $('[name="Email"]').val();
                valid = this.validateEmail(email);

            }

Leave a comment

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