suitescript 2 create customer payments from multiple invoices

Hi Professionals

I am trying to create a customer payment from multiple invoices in suitescript 2 by rest api using suitescript endpoint. Unfortunately, I am unable to create it.

Here is my code  when I execute below code it throws generic error “An unexpected SuiteScript error has occurred”

and error at setSublistValue function

var
log,
search,
runtime,
response = new Object();

define( [ ‘N/log’, ‘N/search’,’N/runtime’,’N/record’ ], main );

function main( logModule, searchModule,runtimeModule,recordModule ) {

log = logModule;
search = searchModule;
runtime = runtimeModule;
record = recordModule;
return { post: postProcess }

}

function postProcess( request ) {
try {

var invoiceId = 703778; // ID of the invoice for which payment is being made
var paymentMethod = “1”; // Payment method (e.g. ‘creditcard’)
var invoiceTotal=130.22;
// Handle form submission
var customerId = 16568;

var payment = record.create({
type: record.Type.CUSTOMER_PAYMENT,
isDynamic: false
});

payment.setValue({
fieldId: ‘customer’,
value: customerId
});

payment.setValue({
fieldId: ‘autoapply’,
value: false
});

payment.setValue({
fieldId: ‘trandate’,
value: new Date()
});

payment.setValue({
fieldId: ‘paymentmethod’,
value: paymentMethod // 1 = Check payment method
});

payment.setSublistValue({
sublistId: ‘apply’,
fieldId: ‘internalid’,
value: invoiceId,
line:1
});

payment.setSublistValue({
sublistId: ‘apply’,
fieldId: ‘amount’,
value: invoiceTotal,
line:1
});

var paymentId = payment.save();
return paymentId;

} catch( e ) {
log.debug( { ‘title’: ‘error’, ‘details’: e } );
return { ‘error’: { ‘type’: e.type, ‘name’: e.name, ‘message’: e.message } }
}
}

Rookie Asked on May 1, 2023 in Billing.
Add Comment
1 Answer(s)

You cannot do this:

payment.setSublistValue({
sublistId: ‘apply’,
fieldId: ‘internalid’,
value: invoiceId,
line:1
});

You should be looking for a line that is already in the list and setting values on that line.

Thanks,

Chris

Advanced Answered on May 3, 2023.

I checked and invoiceId falls in line 1 that’s why I passed it static value in line parameter.

on May 3, 2023.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   SuiteMigration   Become a Sponsor