<@U015L7ELL5Q> Can you show some of the code? In M...
# suitescript
a
@Tyson Eby Can you show some of the code? In Map stage is
context.value
in Reduce stage is
context.values
.
t
@alien4u
Copy code
define(['N/record', 'N/search', 'N/runtime', 'N/format', 'N/email', 'N/render'],
        function(record, search, runtime, format, email, render) {


            //Gets the data from the saved search
            function getInputData() {
                var stLogTitle = 'getInputData';
                try {
                    log.debug(stLogTitle, '*** Start ***');

                    //Gets saved search from script field on script record
					var ssCartAbandId = runtime.getCurrentScript().getParameter('custscript_cartaband_ss');
                    var ssCartAband = search.load({
                        id: ssCartAbandId
                    });
                    return ssCartAband;
					
                } catch (error) {
                    log.error(stLogTitle, 'Error 1: ' + error);
                }
            }


            function map(context) {
                var stLogTitle = 'Map';
                try {
                    log.debug(stLogTitle, '*** Start ***');
                    var searchResult = JSON.parse(context.value);
                    log.debug(stLogTitle, searchResult);

                    //var customerid = searchResult.values['internalid.customer'];
					var customerid = searchResult.values['internalid'];
                    //Creates an object with the needed data
                    var objValues = {
                        itemCart: searchResult.values['shoppingcart.item'],
                        itemCartQty: searchResult.values['shoppingcart.itemqty'],
                        //customerid: searchResult.values['internalid.customer'].value,
						customerid: searchResult.values['internalid'].value,
                        customeremail: searchResult.values['email']
						
						//Gets date the last cart abandonment email was sent
                        //customerlastemailsent: searchResult.values['custentity_aband_cart_email_count.customer']
                    };
                    log.debug(stLogTitle, objValues);

                    context.write({
                        key: customerid,
                        value: objValues
                    });
					
                } catch (error) {
                    log.error(stLogTitle, 'Error 2: ' + error);
                }
            }

            function reduce(context) {
                var stLogTitle = 'reduce';
                try {

                    if (context.values.length > 0) {
                        log.debug(stLogTitle, '*** Start ***');

                        var stToday = new Date();
						
						log.debug(stLogTitle, stToday);

                        //Gets Customer Information
                        var objCart = JSON.parse(context.values[0]);
                        var objCustomer = {
                            id: objCart.customerid,
                            email: objCart.customeremail
                        };
						
						log.debug(stLogTitle, objCustomer);
						
						// Gets email template
                        var stEmailTemplateId = runtime.getCurrentScript().getParameter('custscript_cartaband_email_template');
						
						log.debug(stLogTitle,'Email Template: ' + stEmailTemplateId);

                        //Creates array with items in cart
						var arrCart = [];
                        for (var i = 0; i < context.values.length; i++) {
                            var objValue = JSON.parse(context.values[i]);
                            log.debug(stLogTitle, objValue);
							log.debug(stLogTitle,'Cart Info: ' + objValue.itemCart.value);
                            var objCart = {
								itemCart: objValue.itemCart,
								itemCartQty: objValue.itemCartQty
                            };

                            arrCart.push(objCart);
                        }
                        log.debug(stLogTitle,'Array 1: ' + 'arrCart');
                        log.debug(stLogTitle,'Array 2: ' + arrCart);


                        sendDunningEmail(stEmailTemplateId, objCustomer, arrCart, stToday);


                    }

                } catch (error) {
                    log.error(stLogTitle, 'Error 3: ' + error);
                }
            }
I have
context.value
in map and
context.values
in the reduce function. I believe the shopping cart fields are only searchable within suitescript so I'm hoping to find an alternative. I'm able to load the search with the shopping cart field values but I can't get them passed into the reduce function
b
probably want to share what context.value or context.values looks like
also the error stacktrace, there are multiple places where your code could throw your error