31 January 2012

Inventory Transfer Journal code in ax 2009 / create and post inventory Transfer journal

//following class to post the auto inventory journal posting create object to this class and //pass the record for required values
class ItemTransfer
{
ItemsRequest itemsRequest;
InventJournalTable inventJournalTable;
InventJournalTrans inventjournalTrans;
}
______________
void new(ItemsRequest localItemRequest)
{
FormDataSource fds;
;

fds = localItemRequest.dataSource();
// populates the inventJournalTable table
inventJournalTable = this.populateInventJournalTable();

itemsRequest = fds.getFirst();
while(itemsRequest)
{
// populates the inventJournalTrans table
inventjournalTrans = this.populateInventJournalTrans(inventJournalTable.JournalId);

itemsRequest = fds.getNext();
}
this.createAndPostJournal();// to post the journal
}
_______________
///
/// Populates the buffer of the InventJournalTable table data.
///

///
/// Buffer of the InventJournalTable table.
///

Public InventJournalTable populateInventJournalTable()
{
InventJournalTable journalTable;
InventJournalTableData journalTableData;

journalTable.clear();
journalTable.JournalNameId = ProjParameters::find().TransferJournal;
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;
}
______________
public InventJournalTrans populateInventJournalTrans(InventJournalId _InventJournalId)
{
InventJournalTrans localInventJournalTrans;
InventSum inventSum;
InventQty inventQty;
InventDim fromInventDim,toInventDim;
InventJournalTransData journalTransData;
;

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

// Dimensions from which the transfer performs
fromInventDim.InventSiteId = itemsRequest.FromSite;
fromInventDim.InventLocationId = itemsRequest.FromWarehouse;

/*select firstonly inventSum where inventSum.Itemid == itemsRequest.itemid;
localInventJournalTrans.InventDimid = InventDim::find(inventSum.InventDimId).inventDimId;*/

localInventJournalTrans.InventDimid = InventDim::findOrCreate(fromInventDim).inventDimId;
localInventJournalTrans.initFromInventTable(InventTable::find(itemsRequest.ItemId), False, False);

// Dimensions To which the transfer performs
toInventDim.InventSiteId = itemsRequest.ToSite;
toInventDim.InventLocationId = itemsRequest.ToWarehouse;

toInventDim.inventSiteId = itemsRequest.ToSite;//InventSite.valueStr();
toInventDim.InventLocationId = itemsRequest.ToWarehouse;//InventWareHouse.valueStr();
localInventJournalTrans.ToInventDimId = InventDim::findOrCreate(toInventDim).inventDimId;
localInventJournalTrans.insert();

return localInventJournalTrans;
}
_______________
///
/// Creates and posts the Inventory Transfer Journal.
///

///
/// If there is any exception then the Inventory Journal data is deleted.
///

public void createAndPostJournal()
{

JournalCheckPost journalCheckPost;
;

/*ttsbegin;
//populates the inventJournalTable table
//inventJournalTable = this.populateInventJournalTable();
//populates the inventJournalTrans table
inventjournalTrans = this.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
if(InventJournalCheckpost::newPostJournal(inventJournalTable).validate())
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();
}
}
}
}

__

19 January 2012

Pass the Data Source records to Class or pass the multiple records to class refresh also in AX 2012 / Dynamics 365

LOOP THROUGH SELECTED RECORDS OF A GRID


1. Add a action MenuItem in a form as a MenuItemButton.
2.Take a clicked method()

void clicked()
{
MenuFunction mf;
args args = new Args();
;
args.record(Table1);
mf = new menufunction(identifierstr(classParmData), MenuItemType::Action);
mf.run(args);
}

3.Take a class

class ClassParmData
{
Table1 tb1;// table variable declaration
}
----
public static void main(Args _args)
{
ClassParmData parmData;
Table1 table1;
FormDataSource fds;
;
if(args.record().TableId == tablenum(Table1))
table1 =_ args.record(); // assigning the selected record

fds = _table1.dataSource();// getting the datasource

parmData= new ClassParmData(fds); //passing the form datasource to New() method
or
parmData.parmFormDataSource(fds); // passing the form datasource to parm method to use in other methods

/*table1 = fds.getFirst(); // can loop all the record here also
while(table1)//fds.getNext())
{
info(strfmt(table1.Field1));
table1 = fds.getNext();
}*/

fds.research();// to refresh the form records
}
-----
void new(FormDataSource fdst) // receving the datasource to fdst-FormDataSource
{
;
for(tb1 = fdst.getFirst(true); tb1; tb1 = fdst.getNext()) // fdst.getFirst(True) to select marked records
{
info(strfmt(tb1.Field1));
}
//if you are updating some records in the form write the below line to refresh the data in form.
//fdst.research();
}
void parmFormDataSource(formDataSource fdst)
{
for(tb1 = fdst.getFirst(true); tb1; tb1 = fdst.getNext()) // fdst.getFirst(True) to select marked records
{
info(strfmt(tb1.Field1));
}
//if you are updating some records in the form write the below line to refresh the data in form.
//fdst.research();

}
-----
4. and then select a record in form grid and click a menuitemButton you can see the all datasource records in info.

Ledger Voucher creation Framework and x++ code to create ledger voucher

 Please click her for MS reference file Below is the out of the box example reference and code. SalesInvoiceJournalPostSubBill_Extension->...