Discussions
Stay up-to-date with the latest news from NetSuite. You’ll be in the know about how to connect with peers and take your business to new heights at our virtual, in-person, on demand events, and much more.
New AI Community Guidelines. Please review and follow them to ensure AI use stays safe, accurate, and compliant.
Detecting if a SalesOrder can be billed
Hello NetSuite Community!
I'm trying to write a SuiteScript that determines if a SalesOrder can be billed or not. I'd love a quick set of eyes on the script to see if I've forgotten about any details. Thanks in advance!
function canSalesOrderBeBilled(salesOrderId) { var salesOrderStatus = nlapiLookupField('salesorder', salesOrderId, 'statusRef'); if(salesOrderStatus == 'pendingBilling' || salesOrderStatus == 'pendingBillingPartFulfilled' || salesOrderStatus == 'pendingApproval') { return true; } if(salesOrderStatus == 'billed' || salesOrderStatus == 'closed' || salesOrderStatus == 'cancelled') { return false; } var filters = [ new nlobjSearchFilter('createdfrom', null, 'anyof', salesOrderId) ]; var invoiceResults = nlapiSearchRecord( 'invoice', null, filters, null ); var salesOrderResults = nlapiSearchRecord( 'cashsale', null, filters, null ); if(invoiceResults || salesOrderResults) { return false; } return true; } 0