Monday, January 21, 2019

Get a reference to an Invoice Record on a Customer Payment using SuiteScript

To get a reference on the Invoice Record on a Customer Payment record you may use the "doc" field of the "apply" sublist which is exposed on the  Customer Payment record. Please check the sample code below which obtains the email address under the Messages tab of the Invoice record. Please note the use of doc field of the apply sublist to obitain the internal id of the Invoice record.

function getEmailAddress_beforeRecordSubmit(){
      var count = nlapiGetLineItemCount('apply');

      for(var i = 1; i <= count; i++){
            var isApplied = nlapiGetLineItemValue('apply','apply',i);
            if(isApplied == 'T'){
                  var invId = nlapiGetLineItemValue('apply','doc',i);
                  var emailAdd = nlapiLookupField('invoice',invId,'email');
                  nlapiLogExecution('DEBUG','email = '+emailAdd);
                  // nlapiSetFieldValue('custbody19',emailAdd);

The use case for this is to email the receipt of the customer payment to the email address set on the invoice and not from the email on the customer record. 

No comments:

Post a Comment