Friday, 7 June 2019

How to Void any transaction using SuiteScript 2.0 ?

We should use transaction.void() method to void any transaction.

Imp: After you void a transaction, you cannot make changes to the transaction that impact the general ledger.

If a Void is performed on a transaction, then it returns the ID of the recorded void transaction.

Here is sample code:

var voidCustPaymentId = transaction.void.({
type: record.Type.CUSTOMER_PAYMENT,
id: payment.id <<'Give the Id of the transaction here'>>
});

make sure follow below steps while voiding:

1. In the 'define' function use - N/transaction module,
 Reason is the transaction.void(options) is available in  'N/transaction' module.

2. verify below setup :
    NS ->Go to Setup --> Accounting - > Preferences -> Accounting Preferences:


if the VOID TRANSACTIONS USING REVERSING JOURNALS   field is checked then, we won't see the Void button in the below transactions:

  • Check
  • Bill Payment
  • Payroll Liability Payment
  • Customer Refund
  • Tax Payment
  • Tax Liability Check
  • Customer Payment
and your code will fail.

To avoid this this issue follow make sure you disable the setting and re enable the setting using the code like below:

 use ->'N/config' in the define function.

use below highlighted code:

var revVoid = accountingConfig.getValue('REVERSALVOIDING');

// Uncheck the Reversal flag    
if (revVoid) {
 
           accountingConfig.setValue({
                      fieldId: 'REVERSALVOIDING',
              value: false
            });
accountingConfig.save();

}
//load the payment record
          var paymentValue = record.load({
            type : 'customerpayment',
            id : payment.id
        });
// void the payment record
var voidpayment = transaction.void({
           type: record.Type.CUSTOMER_PAYMENT,
    id: payment.id
      });
       //Reset the reversal flag
accountingConfig.setValue({
fieldId: 'REVERSALVOIDING',
value: true
 });
 accountingConfig.save();
}

This will ensure Accounting settings are not effected.

Note: Make sure if you are using eclipse for suitescripting , some times the transaction.void() results error, this is just because the the jar's are not updated. Ignore the error and load the script in NS, your script should work.


No comments:

Post a Comment