Send Shipped Emails to customers.

             /**
             *
             * Function to send emails once the PRO# and Carriers name are entered
             * @param customer- customer id
             * @param soHash - so document number
             * @param carrierName - carrier name in IF
             * @param proHash - PRO#
             * @param senderId - sender id
             * @param ifRecId - IF record id
             * @param newMemo -memo from IF
             */
            function customerEmail(customer,soHash,carrierName,proHash,senderId,ifRecId,newMemo) {
                    try {
                            var customerLookup = search.lookupFields({
                                    type: search.Type.CUSTOMER,
                                    id: customer,
                                    columns: ['custentity_jj_customerservicerep', 'custentity_jj_email_for_shipping','custentity_jj_operation_email','email']
                            });
                            var operationEmail = customerLookup.custentity_jj_operation_email;

                            var primaryEmail = customerLookup.email;
                            var emailWanttoSent = customerLookup.custentity_jj_email_for_shipping

                            if (emailWanttoSent == true){
                            var sendersList = [];
                            var csrIdDetails = customerLookup.custentity_jj_customerservicerep

                            if (csrIdDetails.length > 0) {
                                    var csrId = csrIdDetails[0].value;
                                    var employeeLookup = search.lookupFields({
                                            type:search.Type.EMPLOYEE,
                                            id: csrId,
                                            columns:['email']
                                    });
                                    var repEmail = employeeLookup.email;
                                    if(repEmail){
                                            sendersList.push(repEmail);
                                    }
                            }
                                    if(operationEmail){
                                            sendersList.push(operationEmail);

                                    }else{
                                            sendersList.push(primaryEmail);

                                    }
                            var emailsSubject

                                    emailsSubject = "Your order(s) from Corp Design has shipped with" + "(" + carrierName + ")" + proHash

                                    //create a table containing IF details.
                                    //table header
                                    var table ='<table style="border: 1px solid black;"><tr style="border: 1px solid black;"><th style="border: 1px solid black; background-color:#808080;">Item Name</th><th style="border: 1px solid black; background-color:#808080;">Quantity</th><th style="border: 1px solid black; background-color:#808080;">Location</th></tr>';

                                    var item, qty, loc;

                                    var itemfulfillmentSearchObj = search.create({
                                            type: "itemfulfillment",
                                            filters:
                                                [
                                                        ["type","anyof","ItemShip"],
                                                        "AND",
                                                        ["cogs","is","F"],
                                                        "AND",
                                                        ["taxline","is","F"],
                                                        "AND",
                                                        ["shipping","is","F"],
                                                        "AND",
                                                        ["internalid","anyof",ifRecId]
                                                ],
                                            columns:
                                                [
                                                        search.createColumn({name: "item", label: "Item"}),
                                                        search.createColumn({name: "quantity", label: "Quantity"}),
                                                        search.createColumn({name: "location", label: "Location"})
                                                ]
                                    });
                                    var searchResultCount = itemfulfillmentSearchObj.runPaged().count;
                                    itemfulfillmentSearchObj.run().each(function(result){
                                            item = result.getText({name: "item", label: "Item"});
                                            qty = result.getValue({name: "quantity", label: "Quantity"});
                                            loc =  result.getText({name: "location", label: "Location"})

                                            table+= '<tr style="border: 1px solid black;"><td style="border: 1px solid black;">'+item+'</td><td style="border: 1px solid black;">'+qty+'</td><td style="border: 1px solid black;">'+loc+'</td></tr>';
                                            return true;
                                    });
                                    table+='</table>';

                            var emailsBody = "Please note that " + newMemo + " from Corp Design has shipped with" + "(" + carrierName + ")" + proHash + "<br/><br/>" + "***Important, please inspect the merchandise when your shipment arrives, look for visual damage, if any, please note POSSIBLE DAMAGE on the BOL and keep a copy for claim purposes." + "<br/><br/>"
                                + "If there is obvious damages, please take pictures immediately, note on the BOL as DAMAGED and the SKU/Qty of each damaged items." +"<br/><br/>"+table+ "<br/><br/>"+"<b>"+"Never refuse/return an order without an RMA# which can be provided by your CSR."+"</b>"+"<br/><br/>"+"In any events, please contact your CSR as soon as possible if you have any issues."+"<br/><br/><br/>" + "Thank you for your business!"

                            email.send({
                                    author: senderId,
                                    recipients: sendersList,
                                    body: emailsBody,
                                    subject: emailsSubject,
                                    relatedRecords: {
                                            transactionId: parseInt(ifRecId)
                                    }
                            });
                            record.submitFields({
                                    type: record.Type.ITEM_FULFILLMENT,
                                    id: ifRecId,
                                    values: {
                                            custbody_jj_csr_email: true
                                    }
                            });
                    }

                    }catch (e) {
                            log.debug("error@customerEmail", e)
                    }
            }

Leave a comment

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