AX – D365FO – Create and post a Transfer InventJournal in Dynamics AX 2012

The sample code below creates a Transfer InventJournal and posts it

public static boolean createInventTransferJournal()
{
    InventDim       fromInventDim;
    InventDim       toInventDim;

    InventJournalNameTransfer   journalIdParameter;
    InventJournalName           transferJournalName;
    InventJournalTable          inventJournalTable;
    InventJournalTable          updateInventJournalTable;
    InventJournalTrans          inventJournalTrans;
    JournalCheckPost            inventJournalCheckPost;  
    ;

    try
    {
        ttsBegin;

        journalIdParameter = InventParameters::find().TransferJournalNameId;

        if (journalIdParameter == '')
        {
            return false;
        }

        transferJournalName = InventJournalName::find(journalIdParameter);

        //Create invent journal header
        inventJournalTable.clear();
        inventJournalTable.initFromInventJournalName(transferJournalName);
        inventJournalTable.Description = 'Whatever description you want to provide'; //Change accordingly
        inventJournalTable.SystemBlocked = true;
        inventJournalTable.insert();
        
        //Create invent journal line - in this example, we create one line.
        //Normally, you'd probably make a loop to create more...
        inventJournalTrans.clear();
        inventJournalTrans.initFromInventJournalTable(inventJournalTable);
        inventJournalTrans.ItemId = '20000039'; //Change accordingly
        inventJournalTrans.LineNum = 1; //Change accordingly
        
        //Set From InventDimId
        fromInventDim.InventLocationId = '001'; //Change accordingly
        fromInventDim.InventSiteId = '012'; //Change accordingly
        fromInventDim.InventSizeId = 'XL'; //Change accordingly
        fromInventDim.InventColorId = 'BLUE'; //Change accordingly
        //TODO: Set other important inventDim properties here if applicable
        fromInventDim = InventDim::findOrCreate(fromInventDim);
                
        //Set To InventDimId
        toInventDim.InventLocationId = '001'; //Change accordingly
        toInventDim.InventSiteId = '012'; //Change accordingly
        toInventDim.InventSizeId = 'XXXL'; //Change accordingly
        toInventDim.InventColorId = 'RED'; //Change accordingly
        //TODO: Set other important inventDim properties here if applicable
        toInventDim = InventDim::findOrCreate(toInventDim);
        
        inventJournalTrans.InventDimId = frominventDim.inventDimId;
        inventJournalTrans.initFromInventTable(InventTable::find('20000039'));
        inventJournalTrans.Qty = 1; //Change accordingly
        inventJournalTrans.ToInventDimId = ToinventDim.inventDimId;
        inventJournalTrans.TransDate = today();
        inventJournalTrans.insert();
        
        //Post journal
        inventJournalCheckPost = InventJournalCheckPost::newJournalCheckPost(JournalCheckpostType::Post, inventJournalTable);
        inventJournalCheckPost.parmThrowCheckFailed(true);
        inventJournalCheckPost.parmShowInfoResult(false);
        inventJournalCheckPost.run();

        select firstOnly forUpdate updateInventJournalTable
            where updateInventJournalTable.RecId == inventJournalTable.RecId;

        updateInventJournalTable.SystemBlocked = false;
        updateInventJournalTable.NumOfLines = 1; //Change accordingly
        updateInventJournalTable.update();

        ttsCommit;
    }
    catch
    {
        ttsAbort;
        return false;
    }

    return true;
}

Rispondi

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo di WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione /  Modifica )

Google photo

Stai commentando usando il tuo account Google. Chiudi sessione /  Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione /  Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione /  Modifica )

Connessione a %s...