View the invoice in the Posting invoice form or perform invoice matching on the invoice and then post

I am facing error when i post invoice through code.
“The result of the invoice matching process for invoice is unknown. View the invoice in the Posting invoice form or perform invoice matching on the invoice and then post.”
How can i solve this?

Jenny,

Are u passing PurchId correct? what code have you written?[:)]

Yes…

[purchParmLine.ReceiveNow,
purchParmLine.RemainBefore,
purchParmLine.RemainAfter] = purchFormLetter.qtyPurch(purchLine, naReal());
[purchParmLine.InventNow,
purchParmLine.RemainBeforeInvent,
purchParmLine.RemainAfterInvent] = purchFormLetter.qtyInvent(purchLine, naReal());
if (purchParmLine.validateWrite())
purchParmLine.update();
else
throw Exception::Error;

This is the code i used. I edit some:

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;
}

Hi Jenny,

Try this code.

static void Dev_CreatePO_and_Invoice(Args _args)
{
NumberSeq numberSeq;
Purchtable Purchtable;
PurchLine PurchLine;
PurchFormLetter purchFormLetter;

;

ttsbegin;
numberSeq = NumberSeq::newGetNumFromCode(purchParameters::numRefPurchaseOrderId().NumberSequence,true);

// Initialize Purchase order values
Purchtable.initValue();
Purchtable.PurchId = numberSeq.num();
Purchtable.OrderAccount = ‘3000’;
Purchtable.initFromVendTable();

if (!Purchtable.validateWrite())
{
throw Exception::Error;
}
Purchtable.insert();

// Initialize Purchase Line items
PurchLine.PurchId = Purchtable.PurchId;
PurchLine.ItemId = ‘B-R14’;
PurchLine.createLine(true, true, true, true, true, false);
ttscommit;

purchFormLetter = purchFormLetter::construct(DocumentStatus::Invoice);
purchFormLetter.update(purchtable, // Purchase record Buffer
“Inv_”+purchTable.PurchId, // Invoice Number
systemdateget()); // Transaction date

if (PurchTable::find(purchTable.PurchId).DocumentStatus == DocumentStatus::Invoice)
{
info(strfmt(“Posted invoiced journal for purchase order %1”,purchTable.PurchId));
}
}

Hye Sudha,

Thank you for your suggestion. The sample you provide is to post invoice directly to the PO. But in my case i have to post the po first, follow by packing slip posting, and finally post the invoice using both the PO and packing slip details. I am using 3 way matching invoice. Unfortunately my code is not working. the error appear asking me to perform invoice matching then try to post. But i have no idea how to do this although the quantity, line number, unit price , itemid and total amount are correctly assigned.