Reseller form

In this extension, we have to add a reseller form with different inputs, when the customer submits with these fields, it will create an prospects in backend

Creation of prosepects

        CreateProspect: function(data) {
            try {
                var FOLDERID = 508097; //Reseller Certificates folder
                var CONTENT = '';

                console.error('In@CreateProspect', data)

                data = JSON.parse(data);

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

                //BODY FIELDS ARE POPULATED HERE
                customerRecord.setFieldValue('entitystatus', 8);
                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]);
                        }
                    }
                }

                if (bodyFields['imageName'] != '') {
                    var fileUploaded = false;
                    var EXTENSION = bodyFields.imageExtn;

                    if (EXTENSION == "PNG" || EXTENSION == "png") {

                        var newFile = nlapiCreateFile(bodyFields['imageName'], 'PNGIMAGE', bodyFields['image']);
                        fileUploaded = true;
                    } else if (EXTENSION == "JPEG" || EXTENSION == "jpeg") {

                        var newFile = nlapiCreateFile(bodyFields['imageName'], 'JPGIMAGE', bodyFields['image']);
                        fileUploaded = true;
                    } else if (EXTENSION == "JPG" || EXTENSION == "jpg") {

                        var newFile = nlapiCreateFile(bodyFields['imageName'], 'JPGIMAGE', bodyFields['image']);
                        fileUploaded = true;
                    }

                    if (fileUploaded) {
                        newFile.setFolder(FOLDERID);
                        var newFileId = nlapiSubmitFile(newFile);
                        customerRecord.setFieldValue('image', newFileId);
                    }
                }
                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");
                }
                var addressFields = data.Address;

                customerRecord.selectNewLineItem('addressbook');
                customerRecord.setCurrentLineItemValue('addressbook', 'defaultshipping', 'T');
                customerRecord.setCurrentLineItemValue('addressbook', 'defaultbilling', 'T');




                var addrSubrecord = customerRecord.createCurrentLineItemSubrecord('addressbook', 'addressbookaddress');

                for (var key in addressFields) {
                    if (addressFields[key] != '') {
                        addrSubrecord.setFieldValue(key, addressFields[key]);
                    }
                }

                addrSubrecord.commit();

                customerRecord.commitLineItem('addressbook');
                //ADDRESS FIELDS END HERE

                var recID = nlapiSubmitRecord(customerRecord); //SAVE RECORD TO GET ID

                //USER NOTES POPULATED HERE
                if (recID) {
                    var userNotes = data.UserFields;

                    var note = nlapiCreateRecord('note');

                    for (var key in userNotes) {
                        if (userNotes[key] != '')
                            note.setFieldValue(key, userNotes[key]);
                    }

                    note.setFieldValue('entity', recID);

                    nlapiSubmitRecord(note);
                }

                //ENDS HERE

                //SEND EMAIL
                var ADMIN = 54718; //protecstyle4@gmail.com
                var RECIPIENT = 'sales@iLoveblvd.com'; //'ravin@jobinandjismi.com';
                var SUBJECT = "A new Prospect has been created from website";
                CONTENT += "Prospect Record ID: " + recID + "<br>";
                CONTENT += "Company Name: " + bodyFields.companyname + "<br>";
                CONTENT += "Phone: " + bodyFields.phone + "<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);


                return JSON.stringify({ success: true });

            } catch (e) {
                console.error('err@sProspect', e)
                return JSON.stringify({ success: false, message: "Something Went Wrong!" });
            }


        }

Also we have used Sweet alert for , customised popup

Leave a comment

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