This article is relevant if you are an NetSuite SuiteScript developer and you are not satisfied with the way NetSuite applies payments to bills.
Automatically Create Checks to Pay Bills
NetSuite does a good job allowing you to select bills to be paid via check. But there may be times you want to do a different way. After working much too long trying all the different ways I could think of (a common phenomenon you are sure to experience when producing SuiteScript), I finally produced the code pattern that will get you there.
// go to dynamic mode so you can find the related sublist item var vendorpayment = new nlapiCreateRecord('vendorpayment', {recordmode: 'dynamic'}); vendorpayment.setFieldValue('entity', <entity id>); vendorpayment.setFieldValue('trandate', nlapiDateToString(nlapiStringToDate(<date>))); vendorpayment.setFieldValue('currency', <currency reference>); vendorpayment.setFieldValue('account', <bank account>); vendorpayment.setFieldValue('autoapply', 'F'); vendorpayment.setFieldValue('memo', <your memo>); vendorpayment.setFieldValue('tranid', <your check id>); //work the line items var lineNum = vendorpayment.findLineItemValue('apply', 'internalid', <related vendorbill internal id>); vendorpayment.selectLineItem('apply', lineNum); vendorpayment.setCurrentLineItemValue('apply', 'apply', 'T'); vendorpayment.setCurrentLineItemValue('apply', 'amount', <amount to apply>); vendorpayment.commitLineItem('apply'); //commit the record var ret = nlapiSubmitRecord(vendorpayment, false, false); nlapiLogExecution('DEBUG', 'Return ID:', ret);
Getting Help
Let me know if you discover other nuances or thinking on this code pattern. If you wish to automate NetSuite, contact us.
Thanks for this script. Used the sublist part to apply vendor credits to vendor bills on a migration that didn’t do this and went unnoticed after go live.
I found the script very useful! QueenBee in the comment before mentions the possibility to use the same idea for applying vendor credits to vendor bills.
How would that look like?
Thanks!
I may be able to post some code. I am in the middle of working on something similar which will create automatic bank deposits.
This is great code. Thanks for sharing after all your hard work. I know this code is a few years old but am wondering if something similar can be done to create Bill Payments to pay intercompany journals.
Thanks!
Hello Stephanie,
I can’t see why not. We have created automated intercompany billing for One World accounts to streamline all the AP/AR between subsidiaries.
Marty
Is it possible to generate Invoice from Sales Order using the same code logic above? I tried but somehow it doesn’t work. The things that I want to achieve here is to generate invoice based on few item fulfillment of the sales order.
Hi Jason,
The key to making this work is to understand that when NetSuite is using the Transform object to create an invoice from a Sales Order, it uses the counters on each line to determine the quantities to invoice. Think of it with this example: Sales Order Quantity = 10, Fulfilled = 5, Invoiced = 2; Netsuite is going want to invoice 3 because Fulfilled – Invoiced = 3. We have had situations where our clients want invoice exactly what was shipped which may be different depending from how the Sales Order sees the “uninvoiced” quantity at the time the invoice routine is called. Thus, to do this, we have to walk all the lines of the underlying generated invoice and modify the quantities. Remember, do not add your own lines or generate an invoice independent of the Sales Order. Doing so disconnects the Sales Order control counters which will lead to other operational concerns.
For a different article that gets into the nitty gritty on this topic, consider this article. https://blog.prolecto.com/2016/04/11/how-to-produce-additional-transactional-financial-information-when-learned-late-in-process/
Hi,
How we can link a bill with purchase. i created a check but i want to link that check with a bill.
Hi Rajitha,
I am not sure I understand your question. You can create purchase orders which can link to vendor bills which can link to payments.
Hey Marty,
Is it possible to use a saved search to find all the credits associated with a bill payment? I can see a list of credits that were applied when the bill payment was created, and that list seems to exist when a payment voucher is created, but I can’t seem to find a way to get that in a saved search. Any Tips?
Thanks!
Did you try the applying to and applied to join Saved Search references? Be careful with mainline = F/T as it may lead to different results.
Hi Marty, thanks for the helpful script! I am running into an issue of transforming Open vendor bills into vendor payments but no line items showing up in the
apply
sublist (i.e. bills to apply the payment to).Can you think of a reason that something similar to the below would occur? (SS2.0 – sorry if code blocks don’t work)
var vendBill = record.load({ type: 'vendorbill', id: 12345})
vendBill.getValue('status')
=> "Open"
var vendPayment = record.transform({
fromType: vendBill.type,
fromId: vendBill.id,
toType: record.Type.VENDOR_PAYMENT,
isDynamic: true });
vendPayment.getLineCount('apply')
=> 0
vendPayment.save();
=> Uncaught SuiteScriptError with Message: "You must enter at least one line item for this transaction"
Hi Max,
Maybe I am missing something because I don’t see where you are turning on the checkboxes to true where you want payment applied.
Marty
Thanks for the response Marty,
I am not turning on any checkboxes because the fundamental problem I’m running into is that there are no checkboxes to check.
When the process is working as expected (i.e. as you’ve detailed above), the transformed vendor payment’s Apply sublist is pre-populated with various open Bills that can be applied via setting the checkbox to true (the open bills would each be a line on the apply sublist and get counted by
.getLineCount('apply')
, but my code snippet shows no open bills aka.getLineCount('apply')
is returning 0). So I’m seeing is a vendor payment with a completely empty Apply sublist.Since the Apply sublist is a List type I can not add/remove lines, or do anything other than edit existing lines. And as there are no line items in the apply sublist (i.e. no checkboxes) I can’t set the ‘apply’ checkbox to true.
Maybe it’d be more helpful to describe it this way (SS 1.0):
vendorpayment.findLineItemValue('apply', 'internalid', );
returns null (i.e. doesn’t find the related vendorbill internal id anywhere because the apply sublist is completely empty)
so
var lineNum = vendorpayment.findLineItemValue('apply', 'internalid', );
lineNum
=> null
and the code crashes on the very next line (
vendorpayment.selectLineItem('apply', lineNum);
) with an error thatlineNum is not defined
One last note is that I’m ensuring there is at least 1 open bill that should pre-populate the apply sublist in my original code snippet by showing that I first load an Open bill, then transform it into a bill payment (so the issue doesn’t seem to be that there are simply no open bills).
Hopefully that makes a bit more sense. Thanks again for the response and assistance.
Something strange is going on here. Have you tried manipulating the form live using the browser console technique as described in this article to confirm you indeed can read values as you see them on the screen?:
https://blog.prolecto.com/2016/02/20/how-to-quickly-update-a-netsuite-read-only-field/
Thank you such much for this post. Helped me a ton!!!! Who’d thunk eight years after posting it would still be helping change the world for the better…
I forgot to mention that be careful when using SS2.0 to make sure the “ignoreFieldChange” is set to false.
rec.setCurrentSublistValue({
sublistId: ‘apply’,
fieldId: ‘amount’,
value: 9.14,
ignoreFieldChange: false
});