Reverse transaction by x++ code

Hi Friends,

Do you know how to reverse a invoice transaction posted by LedgerJournal, in X++ code? Similar to “Reverse” button does in CustTrans Form, but without any dialogue poping up.

Take an example of reversing an customer voucher from customer transactions.

You can use the same code from \Classes\TransactionReversal_Cust\reversal

The code resulting the popup/dialog is if (this.prompt()), you need to make it conditional

If you are calling it from the code then make it not to get executed and set the reverseDate through code.

TransactionReversal_Cust transactionReversal = new TransactionReversal_Cust();

Args args = new Args();

CustTrans custTrans = CustTrans::find(5637145602);

;

args.record(custTrans);

transactionReversal.parmReversalDate(systemdateget());

transactionReversal.reversal(args);

Thanks Kranthi. How to check if the code is called from Form, or from other x++ code? Can it be done by chekcing args.caller()? can you write a line for it?