Original post http://www.agermark.com/2013_02_01_archive.html
PaymentId is set from code in:
\Classes\CustPostInvoice\run (\Classes\CustPostInvoice\runInternal in R3)
\Classes\SalesInvoiceJournalCreateBase\createJournalHeader
You need to choose the the correct payment type for the invoice when doing the invoice update, to get the right payment id calculation.
With the correct payment type you only need to add #isoCountryCode to the container here:
if (SysCountryRegionCode::isLegalEntityInCountryRegion([#isoNO]), numberSeq)
{
moneyTransferSlip = PaymMoneyTransferSlip::construct(custInvoiceJour.GiroType)
moneyTransferSlip.init(custInvoiceJour.GiroType);
moneyTransferSlip.parmNumSeqCode(numberSeq.parmNumberSequenceCode());
paymId = moneyTransferSlip.ocrField(custInvoiceJour.InvoiceAccount,
custInvoiceJour.InvoiceId,
strLen(int2str(NumberSeq::highest(numberSeq.parmNumberSequenceId()))));
custInvoiceJour.PaymId = strLRTrim(paymId);
}