Tuesday, June 4, 2019

Sample Script to Apply a Customer Refund to Credit Memo

Below is a sample script on how to apply a Customer Refund to a Credit Memo. The field sourcing for the apply sublist is triggered by the Dynamic Mode record creation.

 var applyIdToApply = {selected credit memo ID};
 var custID = {selected customer ID};
 var acctID = {selected account ID};
 var paymethID = {selected payment method ID};
 var rec = nlapiCreateRecord('customerrefund', {recordmode:'dynamic'} );
 rec.setFieldValue('customer',custID);
 rec.setFieldValue('account',acctID);
 rec.setFieldValue('paymentmethod',paymethID);
 var lineCount = rec.getLineItemCount('apply');
 nlapiLogExecution('DEBUG','lines',lineCount);
 for(var i=1; i<= lineCount;i++){
  rec.selectLineItem('apply', i);
  var applyID = rec.getCurrentLineItemValue('apply', 'doc');
        var amountRemaining = rec.getCurrentLineItemValue('apply', 'due');
        nlapiLogExecution('DEBUG','applyID : amountRemaining : applyIdToApply',applyID + ' : ' + amountRemaining + ' : ' +applyIdToApply);
  if ( applyID == applyIdToApply ) {
           rec.setCurrentLineItemValue('apply', 'apply', 'T');
           rec.setCurrentLineItemValue('apply', 'amount', amountRemaining);
           rec.commitLineItem('apply');
        }
 }
 var newRecord = nlapiSubmitRecord(rec, true, false);


DISCLAIMER: The sample code described herein is provided on an "as is" basis, without warranty of any kind, to the fullest extent permitted by law. NetSuite Inc. does not warrant or guarantee the individual success developers may have in implementing the sample code on their development platforms or in using their own Web server configurations.

NetSuite Inc. does not warrant, guarantee or make any representations regarding the use, results of use, accuracy, timeliness or completeness of any data or information relating to the sample code. NetSuite Inc. disclaims all warranties, express or implied, and in particular, disclaims all warranties of merchant-ability, fitness for a particular purpose, and warranties related to the code, or any service or software related thereto.
NetSuite Inc. shall not be liable for any direct, indirect or consequential damages or costs of any type arising out of any action taken by you or others related to the sample code.

No comments:

Post a Comment