/**
* @NApiVersion 2.1
* @NScriptType MapReduceScript
* @NModuleScope SameAccount
*/
define([ 'N/runtime', 'N/record', 'N/search'],
(runtime, record, search) => {
getInputData = (context) => {
log.debug('==START==','==START==');
let customers = [
324
];
return customers;
}
map = (context) => {
try {
let customerId = context.value;
let paymentRecord = record.create({
type: record.Type.CUSTOMER_PAYMENT,
isDynamic: true
});
paymentRecord.setValue('customer', customerId);
// apply invoices
let lineCount = paymentRecord.getLineCount({sublistId: 'apply'});
for (let i = 0; i < lineCount; i++) {
let currentLine = paymentRecord.selectLine({sublistId: 'apply',line: i});
paymentRecord.setCurrentSublistValue({sublistId: 'apply',fieldId: 'apply',value: true});
paymentRecord.commitLine({sublistId: 'apply'});
}
// apply deposits
let lineCount = paymentRecord.getLineCount({sublistId: 'deposit'});
for (let i = 0; i < lineCount; i++) {
let currentLine = paymentRecord.selectLine({sublistId: 'deposit',line: i});
paymentRecord.setCurrentSublistValue({sublistId: 'deposit',fieldId: 'apply',value: true});
paymentRecord.commitLine({sublistId: 'deposit'});
}
let paymentId = paymentRecord.save();
if (paymentId) {
// payment created in error, delete and show error
record.delete({
type: record.Type.CUSTOMER_PAYMENT,
id: paymentId
});
log.error('ERROR', 'Incorrectly created a customer payment record for customer' + customerId);
}
else {
log.debug('Success','Successfully applied payments to invoices for customer ' + customerId);
}
}
catch(e) {
log.error('Error', JSON.stringify(e));
}
}
summarize = (summary) => {
log.debug('==END==','==END==');
}
return {
getInputData: getInputData,
map: map,
summarize: summarize
};
});
Jaime Requena is a seasoned NetSuite Consultant and Solutions Architect, known for delivering WHITE GLOVE service to businesses. With 15+ years of experience and 3x certifications in ERP, Developer, and Admin, Jaime specializes in highly customized NetSuite accounts, transforming operations for 200+ satisfied customers all across the globe.
We aim to bring unmatched expertise and professionalism to your NetSuite initiatives. Let’s talk about how our NetSuite consultancy can make a difference!
It’s Been 4+ Years Now And We Have Worked With Hundreds Of Clients, Building Our Way To The Top, One Happy Client After Another! Their Voices Of Satisfaction Serve As A Testament To Our Success –