I'm am pretty new to Dynamics AX 2009 and since I haven't really found the way to solve what I'm doing I decided to ask here.
I have a requirement to post(?) an invoice through X++.
I already found this HOWTO: Facturación selectiva de líneas en Dynamics AX and even though it's in Spanish I think you will get the idea.
Here is the code I modified from the link:
static void JAEE_PurchFormLetter(Args _args)
{
Num _invoiceNum; // Núm. factura
TransDate _invoiceDate; // Fecha factura
MyPurchFormLetter purchFormLetter = PurchFormLetter::construct(DocumentStatus::Invoice);
PurchParmUpdate purchParmUpdate;
PurchParmTable purchParmTable;
PurchParmLine purchParmLine;
TradeLineRefId tableRefId;
PurchTable purchTable;
PurchLine purchLine;
;
ttsbegin;
_invoiceNum = 'Facbyjob';
_invoiceDate = str2date('14-01-2013', 123);
purchTable = PurchTable::find('00000019_062'); // Primer pedido
// Inizializar purchFormLetter con el primer pedido
purchFormLetter.parmCallerTable(purchTable);
purchFormLetter.callInitParmPurchTable(purchTable);
purchFormLetter.proforma(false); // Proforma: NO (Registrar: SI)
purchFormLetter.enableUpdateNowField(true); // Actualizar ahora: SI
purchFormLetter.printFormLetter(false); // Imprimir: NO
purchFormLetter.transDate(_invoiceDate); // Fecha de factura
// Inizializar purchParmUpdate con el primer pedido
purchParmUpdate.clear();
purchParmUpdate.initValue();
purchParmUpdate.ParmId = purchFormLetter.parmId();
purchParmUpdate.SumBy = AccountOrder::Account; // Agrupar por cliente
purchParmUpdate.SumNum = _invoiceNum; // Núm. Factura
purchParmUpdate.SpecQty = PurchUpdate::All; // Actualizar: Todo
purchParmUpdate.DocumentStatus = DocumentStatus::Invoice; // Tipo documento: Factura
purchParmUpdate.Proforma = NoYes::No; // Proforma: NO
purchParmUpdate.SumIncludePending = NoYes::No; // Incluir pendiente: NO
if (purchParmUpdate.validateWrite())
purchParmUpdate.insert();
else
throw Exception::Error;
purchFormLetter.purchParmUpdate(purchParmUpdate);
purchFormLetter.parmParmTableNum(purchParmUpdate.SumNum);
// Tabla temporal, se crea un registro de cabecera del primer pedido (sólo uno)
purchParmTable.clear();
purchParmTable.TableRefId = FormLetter::getTableRef();
purchFormLetter.createParmTable(purchParmTable, purchTable);
if (purchParmTable.validateWrite())
purchParmTable.insert();
else
throw Exception::Error;
tableRefId = purchParmTable.TableRefId;
// BEGIN - LINEAS
// - Repetir para cada línea que se quiera facturar y para cada una y
// - asignar las variabies purchTable y purchLine según proceda
purchParmLine.clear();
purchParmLine.initValue();
// Ajustar cantidades según necesidades
// Catnidades de compra
[purchParmLine.ReceiveNow,
purchParmLine.RemainBefore,
purchParmLine.RemainAfter] = purchFormLetter.qtyPurch(purchLine, naReal());
// Cantidades de inventario
[purchParmLine.InventNow,
purchParmLine.RemainBeforeInvent,
purchParmLine.RemainAfterInvent] = purchFormLetter.qtyInvent(purchLine, naReal());
if (purchParmLine.ReceiveNow)
{
purchParmLine.ParmId = purchParmUpdate.ParmId;
purchParmLine.initFromPurchLine(purchLine);
purchParmLine.setLineAmount();
purchParmLine.TableRefId = tableRefId;
if (purchParmLine.validateWrite())
purchParmLine.insert();
else
throw Exception::Error;
}
// END - LINEAS
// Registrar!
purchFormLetter.reArrangeNow(false); // No organizar
purchFormLetter.run();
ttscommit;
}
My question is in this line: purchFormLetter.callInitParmPurchTable(purchTable);
.
Why should initParmPurchTable()
be called from within a derived class of PurchFormLetter?
And also, how to accomplish this? I tried declaring my own class MyPurchFormLetter
which extends PurchFormLetter
, adding the callInitParmPurchTable()
method but compiler tells me that the object does not have the method when I try to run the code.
It reads:
Error al ejecutar código: Object objeto no tiene el método 'callInitParmPurchTable'.
EDIT:
What I have done is add the method into the class, in such a way that callInitParmPurchTable()
is part of the object. But I am leaving the question open since I don't think this is the right approach.
I have found out the following:
It is correct to make a class that inherits from PurchFormLetter
and implement there the method callInitParmPurchTable()
which obviously is the one that executes initParmPurchTable()
.
Most likely the one part that I had been missing was to compile MyPurchFormLetter
so that the compiler could tell the method existed.