Learn the NetSuite SuiteScript 2.0 Pattern to Apply Customer Deposits to Invoices

This article is relevant if you need to see a NetSuite SuiteScript 2.0 code snippet for how to apply a customer deposit record to an invoice.

Background

In my article, Use NetSuite SuiteScript to Automate Posting Customer Deposits to Invoices, I offered a SuiteScript 1.0 pattern to apply customer deposit amounts to invoices. These days, we are working in SuiteScript 2.0. So here is the related code pattern.

NetSuite SuiteScript 2.0 Apply Customer Deposits to Open Invoices

Here is the code snippet developed by one of our consultants working an application to apply unlinked customer deposits to an invoice.

//code snippet to apply a customer deposit to an open invoice
var rcdDepositApplication = record.transform({	
	fromType: record.Type.CUSTOMER_DEPOSIT,
	fromId:CustDepositId,
	toType: record.Type.DEPOSIT_APPLICATION,
	isDynamic: true });

rcdDepositApplication.setValue('trandate' , new Date());
rcdDepositApplication.setValue('memo'     , 'Created via the utility on ' + new Date());

//loop the lines and find the InvoiceId (code not shown) to apply funds: assumption is that we are applying
//the total amount due
var nbrLines = rcdDepositApplication.getLineCount({ sublistId: 'apply' });
for (var ix = 0; ix < nbrLines; ix++){
	var sublistInvoiceId = rcdDepositApplication.getSublistValue({ sublistId:'apply' ,fieldId:'internalid' ,line:ix });
	if ( sublistInvoiceId == InvoiceId ){
		var SublistDue = rcdDepositApplication.getSublistValue({ sublistId:'apply' ,fieldId:'due' ,line:ix });
		rcdDepositApplication.selectLine({ sublistId:'apply' ,line:ix });
		rcdDepositApplication.setCurrentSublistValue({ sublistId:'apply' ,fieldId:'amount' ,value:SublistDue ,ignoreFieldChange:false});
		rcdDepositApplication.setCurrentSublistValue({ sublistId:'apply' ,fieldId:'apply'  ,value:true       ,ignoreFieldChange:false});
	}
}
rcdDepositApplication.save();

Be Appreciated for Your Capacity to Innovate

If you feel you hold high standards for care and you want to be appreciated for your ability to design, craft and build NetSuite solutions, perhaps it makes sense to have a conversation about career opportunities?

Be Sociable, Share!

Marty Zigman

Holding all three official certifications, Marty is Southern California's NetSuite expert and leads a team of senior professionals at Prolecto Resources, Inc. He is a former Deloitte & Touche CPA and has held CTO roles. For over 25 years, Marty has produced leadership in ERP, CRM and eCommerce business systems. Contact Marty to set up a conversation.

More Posts - Website - Twitter - Facebook - LinkedIn - Google Plus - YouTube

| Category: NetSuite, Technical | Leave a comment

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>