Thursday, January 26, 2012

post inventory journal using code

recently i have written a quick code to to post the invent transfer jounral


/// <summary>
/// Populates the buffer of the <c>InventJournalTable</c> table data.
/// </summary>
/// <returns>
/// Buffer of the <c>InventJournalTable</c> table.
/// </returns>
Public InventJournalTable populateInventJournalTable()
{
    InventJournalTable      journalTable;
    InventJournalTableData  journalTableData;

    journalTable.clear();
    journalTable.JournalNameId  = InventParameters::find().QuickTransferJournalNameId;
    journalTableData            = JournalTableData::newTable(journalTable);
    journalTable.JournalId      = journalTableData.nextJournalId();
    journalTable.Reservation    = ItemReservation::Automatic;
    journalTable.JournalType    = InventJournalType::Transfer;
    journalTableData.initFromJournalName(journalTableData.JournalStatic().findJournalName(journalTable.journalNameId));
    journalTable.Description    = InventDescription.valueStr();
    journalTable.insert();

    return journalTable;
}


/// <summary>
/// Populates the buffer of the <c>InventJournalTrans</c> table data.
/// </summary>
/// <param name="_InventJournalId">
/// <c>JournalId</c> of the <c>InventJournalTable</c>
/// </param>
/// <returns>
/// Buffer of the <c>InventJournalTrans</c> table.
/// </returns>
public InventJournalTrans populateInventJournalTrans(InventJournalId _InventJournalId)
{
    InventJournalTrans inventJournalTrans;
    InventDim          toInventDim;

    inventJournalTrans.JournalId      = _InventJournalId;
    inventJournalTrans.JournalType    = InventJournalType::Transfer;
    inventJournalTrans.TransDate      = systemdateget();
    inventJournalTrans.ItemId         = inventSum.ItemId;
    inventJournalTrans.Qty            = InventQty.realValue();

    // Dimensions from which the transfer performs
    inventJournalTrans.InventDimId    = inventDimLocal.inventDimId;
    inventJournalTrans.initFromInventTable(InventTable::find(inventSum.ItemId), False, False);

    // Dimensions To which the transfer performs
    toInventDim.inventSiteId         = InventSite.valueStr();
    toInventDim.InventLocationId     = InventWareHouse.valueStr();
    inventJournalTrans.ToInventDimId = InventDim::findOrCreate(toInventDim).inventDimId;
    inventJournalTrans.insert();

    return inventJournalTrans;
}

/// <summary>
/// Creates and posts the Inventory Transfer Journal.
/// </summary>
/// <remarks>
/// If there is any exception then the Inventory Journal data is deleted.
/// </remarks>
public void createAndPostJournal()
{
    InventJournalTable      inventJournalTable;
    InventJournalTrans      inventjournalTrans;
    JournalCheckPost        journalCheckPost;

    ttsbegin;

    // populates the inventJournalTable table
    inventJournalTable = element.populateInventJournalTable();

   // populates the inventJournalTrans table
    inventjournalTrans = element.populateInventJournalTrans(inventJournalTable.JournalId);

    ttsCommit;

    if (BOX::yesNo('Do you want to post the Journal ? ', DialogButton::Yes) == DialogButton::Yes)
    {
        // Call the static method to create the journal check post class
        journalCheckPost = InventJournalCheckPost::newPostJournal(inventJournalTable);

        if(journalCheckPost.validate())
        {
            try
            {
                journalCheckPost.run();
            }
            catch
            {
                // Deletes the InventJournalTable table, the InventJournalTrans will auto delete because of the Delete actions.
                InventJournalTable.delete();
            }
        }
     }
}


18 comments:

  1. how about

    // Dimensions To which the transfer performs
    toInventDim.inventSiteId = InventSite.valueStr();
    toInventDim.InventLocationId = InventWareHouse.valueStr();

    Where are declared those objects (InventSite, InventWareHouse);

    ReplyDelete
    Replies
    1. There is a form that is created by BOF framework gets the input from user, these control are in that form. Here i put just the method that is do the posting of inventory journal.

      Delete
  2. Thanks for the great information it worked fine, but i don't know how to post Inventory journal with allow transfer error to new journal.

    could you help me with this please.

    ReplyDelete
  3. I would be interested to know how I can put this to use. Is this code an alternative to standard Ax?
    But most particularly - are you distinguishing between "Detail" and "Summary" option. We would LOVE it if the Summary option produced no GL journal if there was no financial impact of the transfer. At present we transfer from one Configuration to another - but when there is no cost change, we get 4 Journal lines that nett to zero for both Inventory and Adjustment GL accounts!

    ReplyDelete
  4. I would be interested to know how I can put this to use. Is this code an alternative to standard Ax?
    But most particularly - are you distinguishing between "Detail" and "Summary" option. We would LOVE it if the Summary option produced no GL journal if there was no financial impact of the transfer. At present we transfer from one Configuration to another - but when there is no cost change, we get 4 Journal lines that nett to zero for both Inventory and Adjustment GL accounts!

    ReplyDelete
  5. How to populate financial dimensions on to transfer journal line, thanks in advance.

    ReplyDelete
    Replies
    1. inventSiteDimensionLink = inventSiteDimensionLink::newDimensionTables(inventJournalTrans, frominventDim);
      inventSiteDimensionLink.linkDimension();

      Delete
  6. inventSiteDimensionLink = inventSiteDimensionLink::newDimensionTables(inventJournalTrans, frominventDim);
    inventSiteDimensionLink.linkDimension();

    ReplyDelete
  7. Good post please visit here to get more technical material for ax


    http://daynamicsaxaptatutorials.blogspot.com

    ReplyDelete
  8. How are you handling Voucher here?
    I am getting "Voucher number must be filled in" where Selection by field for Journal name points to "Entry". If I make it "Posting" it does work.

    ReplyDelete