I am trying to create a vendorpayment record using script. This is my script.
var transactionId = '11111';
var vendorId = '222';
var subsidiaryId = '2';
var apAccountId = '333'
var inputAmount = 1000;
var currencyId = '4'; //USD
var make_billPayment_record = record.create({
type: 'vendorpayment',
defaultValues: { entity: vendorId, subsidiary: subsidiaryId, apacct: apAccountId }
});
if(!!currencyId){make_billPayment_record.setValue({ fieldId: 'currency', value: currencyId });}; //Currency
if(!!bankAccountId){make_billPayment_record.setValue({ fieldId: 'account', value: bankAccountId });}; //Account
if(!!departmentId){make_billPayment_record.setValue({ fieldId: 'department', value: departmentId });}; //Department
if(!!classId){make_billPayment_record.setValue({ fieldId: 'class', value: classId });}; //Cash Flow Segment
if(!!exchangeRate){make_billPayment_record.setValue({ fieldId: 'exchangerate', value: parseFloat(exchangeRate) });}; //Exchange Rate
make_billPayment_record.setValue({ fieldId: 'custbody_9997_is_for_ep_eft', value: true }); //For Electronic Bank Payment
var apply_numLines = make_billPayment_record.getLineCount({sublistId: 'apply'});
for(i = 0; i < apply_numLines; i++){
var lineTxnId = make_billPayment_record.getSublistValue({
sublistId: 'apply',
fieldId: 'internalid',
line: i
});
if(parseFloat(lineTxnId) == parseFloat(transactionId)){
make_billPayment_record.setSublistValue({
sublistId: 'apply',
fieldId: 'apply',
line: i,
value: true
});
make_billPayment_record.setSublistValue({
sublistId: 'apply',
fieldId: 'amount',
line: i,
value: parseFloat(inputAmount)
});
}
};
var created_bp_id = make_billPayment_record.save({ enableSourcing: true, ignoreMandatoryFields: true });
I am aware that you cannot create a list on vendorpayment, it is preloaded based on the vendor, subsidiary and currency and you have to iterate each line and apply the transaction. The thing that I am having trouble with is initializing that list. When I do record.create with default values, the initialized sublist data does not contain the apply line that I am looking for because the default currency being set is different. When I add currency as a default value on my record.create, Netsuite is giving me an error {“name”:”INVALID_RCRD_INITIALIZE”,”message”:”You have entered an invalid default value for this record initialize operation.”}. I also tried creating a vendorpayment record without applying any transactions first but Netsuite is also giving me an error “You must enter at least one line item for this transaction.”
If I can’t initialize record.create with currencyId, I can’t get the correct apply sublist data.
If initializing record with currencyId is not possible, is there a way for me to get the correct apply sublist? Or is there a different way to achieve what I am trying to do?
Any help would be appreciated, thanks.
