Marty Zigman

Conversations with Marty Zigman

Certified Administrator • ERP • SuiteCloud

Automate Creating Checks to Pay Bills in NetSuite

NetSuite Technical

Tags: , , , ,

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.

 

Marty Zigman LinkedIn

Marty Zigman

Holding three official certifications, Marty is widely recognized as a top NetSuite expert and leads a team of senior professionals at Prolecto Resources, Inc. A former Deloitte & Touche CPA and technology executive with CTO roles, he brings over 35 years of leadership in ERP, CRM, and eCommerce business systems. Contact Marty to engage directly.

BiographyYouTubeLinkedInX (Twitter)

17 thoughts on “Automate Creating Checks to Pay Bills in NetSuite

  1. 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.

    Reply
  2. 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!

    Reply
  3. 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!

    Reply
  4. 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.

    Reply
  5. 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!

    Reply
  6. 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"

    Reply
  7. 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 that lineNum 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.

    Reply
  8. 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…

    Reply
  9. 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
    });

    Reply

Leave a Reply

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