The saved search for checking whether the item is parent or child in the custom matrix item

 getItems: function (data) {
                try {
                    console.error(JSON.stringify(data));
                    var sub = data.sub;
                    var condition = data.cld === "T";
                    var filter = [[[[["parent", "anyof", "@NONE@"], "AND", [["custitem_jj_haschildren", "is", "F"], "OR", ["custitem_jj_haschildren", "is", "T"]]]],"OR",["matrixchild", "is", "F"]],
                        "AND",
                    ["isavailable", "is", "T"],
                        "AND",
                    ["custitem_retailitem", "is", "T"],
                        "AND",
                    ["subsidiary", "anyof", "2"]];
                    if (condition) {
                        filter.push("AND")
                        filter.push(['custitem_ecommerceproductstatus', 'anyof', "2"])
                    } else {
                        filter.push("AND")
                        filter.push(['custitem_ecommerceproductstatus', 'noneof', "2"])
                    }
                    if (data.catid != "") {
                        filter.push("AND")
                        filter.push(['custitem_category_custom', 'anyof', data.catid])
                    }
                    var columns = [
                        new nlobjSearchColumn("itemid", null, "GROUP").setSort(false),
                        new nlobjSearchColumn("displayname", null, "GROUP"),
                        new nlobjSearchColumn("internalid", null, "GROUP"),
                        new nlobjSearchColumn("custitem_chr_units_per_pallet", null, "GROUP"),
                        new nlobjSearchColumn("custitem_category_custom", null, "GROUP"),
                        new nlobjSearchColumn("upccode", null, "GROUP"),
                        new nlobjSearchColumn("custitem_rfs_packing_length", null, "GROUP"),
                        new nlobjSearchColumn("custitem_rfs_packing_width", null, "GROUP"),
                        new nlobjSearchColumn("custitem_rfs_packing_height", null, "GROUP"),
                        new nlobjSearchColumn("weight", null, "GROUP"),
                        new nlobjSearchColumn("custitem_jj_haschildren", null, "GROUP"),
                        new nlobjSearchColumn("parent", null, "GROUP"),
                        new nlobjSearchColumn("baseprice", null, "GROUP"),
                        new nlobjSearchColumn("custitem_retailitem", null, "GROUP"),
                        new nlobjSearchColumn("custitem_ecommerceproductstatus", null, "GROUP")
                    ];
                    var search = Application.getPaginatedSearchResults({
                        results_per_page: 20,
                        columns: _.values(columns),
                        filters: filter,
                        record_type: 'item',
                        page: data.page || 1,
                    });

                    if (search.records) {
                        var self = this;
                        var items = [];

                        var returnRecord = _.map(search.records, function mapRecord(result) {
                            var resultObj = JSON.parse(JSON.stringify(result));
                            console.error(JSON.stringify(resultObj));
                            var itemid = result.getValue('internalid', null, 'GROUP');
                            items.push(itemid);
                            return {
                                id: result.getValue('internalid', null, 'GROUP'),
                                itemid: result.getValue('itemid', null, 'GROUP'),
                                displayname: result.getValue('displayname', null, 'GROUP'),
                                matrixitem: result.getValue('custitem_jj_haschildren', null, 'GROUP'),
                                parent: result.getValue('parent', null, 'GROUP'),
                                category: result.getText('custitem_category_custom', null, 'GROUP'),
                                pallet: result.getValue('custitem_chr_units_per_pallet', null, 'GROUP'),
                                upccode: result.getValue('upccode', null, 'GROUP'),
                                length: result.getValue('custitem_rfs_packing_length', null, 'GROUP'),
                                width: result.getValue('custitem_rfs_packing_width', null, 'GROUP'),
                                height: result.getValue('custitem_rfs_packing_height', null, 'GROUP'),
                                weight: result.getValue('weight', null, 'GROUP'),
                                baseprice: result.getValue('baseprice', null, 'GROUP'),
                                retailitem: result.getValue("custitem_retailitem", null, 'GROUP'),
                                status: result.getValue("custitem_ecommerceproductstatus", null, 'GROUP')
                            };
                        });
                        var imgUrl = self.getItemImageUrl(items);

                        _.each(returnRecord, function (item) {
                            var matchingImage = _.find(imgUrl, function (img) {
                                return img.id === item.id;
                            });
                            if (matchingImage) {
                                item.thumbnail = matchingImage.url;
                            }
                        });
                        search.records = returnRecord;
                    }
                    if (data.catid != "") {
                        search.categoryType = nlapiLookupField('customrecord_commerce_category', data.catid, 'name');
                    }
                    return search;
                } catch (error) {
                    console.error(JSON.stringify(error));
                    return {
                        code: "500",
                        message: "error"
                    };
                }

            },

Leave a comment

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