cancel
Showing results for 
Search instead for 
Did you mean: 

How to cancel Journal Entry Voucher from ABSL code

kostadin_terziev
Participant
0 Kudos

Hello!

I am having trouble reversing/cancelling a journal entry voucher from ABSL code.

The idea is to reverse a custom JEV created on release of customer invoice when the invoice is cancelled.

For that I use internal communication from Customer Invoice object (sender) to a custom receiver object in the deployment unit Financials, so that i can call JEV.Cancel() from that custom receiver object.

When debugging the jev.cancel() is called and the status of the jev is set to cancelled. However when checking the UI in the system, it still shows the status of the JEV as Posted.

Do i need to do something before calling the cancel action? What am i doing wrong?

Here is the code i use in my receiver object.

import ABSL;
import AP.Common.GDT;
import AP.CustomerInvoicing.Global;
import AP.FinancialAccounting.Global;
import AP.DueItemManagement.Global;

var invoice = CustomerInvoice.Retrieve(this.invoiceUUID);
var isInvoiceCancelled = false;
if (invoice.IsSet()) {
	var releaseCancelled = invoice.Status.ReleaseStatusCode.Matches("5");
	if (releaseCancelled && !invoice.CancellationDocumentIndicator) {
		isInvoiceCancelled = true;
	}
}

// DP INVOICE CANCELLATION HANDLER:
if (this.invoiceCancelled || isInvoiceCancelled) {
	// check if the invoice is cancelled and then reverse the journal entry
	var key : AccountingEntryKey;
	key.ID = this.jevID;
	key.CompanyUUID = invoice.BillFromParty.PartyUUID;
	var jev = AccountingEntry.Retrieve(key);
	jev.Cancel();
	// raise message that jev has been cancelled
	if (jev.Status.PostingStatusCode.Matches("4")) {
		raise MsgJEVCancelled.Create("S", jev.ID);
	}
}<br>
View Entire Topic
dominik_g
Participant

Hi Kostadin,

action Cancel() for the Journal Entry Voucher (AccountingEntry) BusinessObject requires parameters.

import ABSL;
import AP.FinancialAccounting.Global;
import AP.Common.GDT as apCommonGDT;

var filtered = this.toAccountingEntry.Where(n => n.Status.PostingStatusCode == "3") ; //3 = Posted

if(filtered.Count() > 0) {
	foreach(var jev in filtered) { 
		var paramPostingDate = jev.PostingDate;

		var paramPostingDate = ABSL:Date.ParseFromString("2022-11-15");
		var paramNote : SHORT_Note = jev.Note;
		var paramAccountingClosingStepCode : AccountingClosingStepCode;
		jev.Cancel(paramPostingDate, paramNote, paramAccountingClosingStepCode);
	}
}

Best regards

Dominik

kostadin_terziev
Participant
0 Kudos

Actually, it works without parameters too.

The problem was that the validation script on save for my custom receiver object was giving an error and thus not saving.

I saw in one article that if you are trying to modify a business object from a custom business object, both objects' validation scripts have to return true on save, otherwise neither of them will be saved.

So if the custom object is not saved to the database, neither will the accounting entry.