https://dhruvrthakar.blogspot.com/2018/07/how-to-create-ssrs-report-in-d365.html
X++ Code Create movement journal
Create movement journal using X++
class CreateMovementJournal
{
public static void main(Args _args)
{
InventJournalTable inventJournalTable;
InventJournalTrans inventJournalTrans;
InventJournalNameId inventJournalNameId;
InventJournalName inventJournalName;
InventDim inventDim;
DimensionAttributeValueCombination dimAttrValueCombo;
int numOfLines = 0;
ttsbegin;
//Below code creates journal header
inventJournalTable.clear();
inventJournalNameId = InventJournalName::standardJournalName(InventJournalType::Movement);
inventJournalTable.initFromInventJournalName(InventJournalName::find(inventJournalNameId));
inventJournalTable.insert();
//Below code creates a single line
inventJournalTrans.clear();
inventJournalTrans.initFromInventJournalTable(inventJournalTable);
inventJournalTrans.TransDate = systemDateGet();
inventJournalTrans.ItemId = '1000'; //Replace the ItemId according to your data
inventJournalTrans.initFromInventTable(InventTable::find(inventJournalTrans.ItemId));
inventJournalTrans.Qty = 1; //Replace the Qty according to your data
inventdim.InventSiteId = '1'; //Replace the InventSiteId (Site) according to your data
inventdim.InventLocationId = '11'; //Replace the InventLocationId (Warehouse) according to your data
inventJournalTrans.InventDimId = InventdIm::findOrCreate(inventDim).inventDimId;
dimAttrValueCombo.clear();
select firstonly RecId from dimAttrValueCombo
where dimAttrValueCombo.MainAccount == MainAccount::findByMainAccountId("110110").RecId //Replace the MainAccountId according to your data
&& dimAttrValueCombo.DisplayValue == '110110'; //Replace the MainAccountId according to your data
inventJournalTrans.LedgerDimension = dimAttrValueCombo.RecId;
//Insert line to movement journal if quantity is non-zero
if(inventJournalTrans.Qty > 0)
{
numOfLines++;
inventJournalTrans.insert();
}
//updating number of lines field at header level of Movement Journal
inventJournalTable.NumOfLines = numOfLines;
inventJournalTable.update();
ttscommit;
info(strFmt("Movement Journal ID: %1", inventJournalTable.JournalId));
}
}
Create customer through X++
Class runner — Finance and Operations (dynamics.com)
Second, change ‘&mi=DefaultDashboard’ and replace it with ‘&mi=SysClassRunner‘. This tells the system to run a class.
Third, add the following text to the end of the URL: ‘&cls=<TheNameOfYourClass>‘. Replace <TheNameOfYourClass> with the name of your class. In the example above, it would be TestRunnableClass.
The final format of your URL should be:
https://<URL of your D365 environment>/?cmp=<YourCompany>&mi=SysClassRunner&cls=<TheNameOfYourClass>
https://rsmta-peter1234567aos.cloudax.dynamics.com/?mi=SysClassRunner&cls=TestRunnableClass
Finally, copy this URL into your browser, and hit enter. The browser will then run the D365 runnable class (job). You will see the message ‘Class ‘<TheNameOfYourClass>’ completed’ once your job has finished running.
class GD_RunIntegration
{
/// <summary>
/// Runs the class with the specified arguments.
/// </summary>
/// <param name = “_args”>The specified arguments.</param>
publicstaticvoid main(Args _args)
{
SamCustomServiceTest::JobCreateCustomer();
}
}
class SamCustomServiceTest{ static void JobCreateCustomer () { CustTable custTable; NumberSeq numberSeq; Name name ='SouthSide Street GVND'; DirParty dirParty; DirPartyPostalAddressView dirPartyPostalAddressView; DirPartyContactInfoView dirPartyContactInfo; ; /* Marks the beginning of a transaction. Necessary to utilize the method numRefCustAccount() */ ttsBegin; custTable.initValue(); try { //CustTable numberSeq = NumberSeq::newGetNum(CustParameters::numRefCustAccount()); custTable.AccountNum = numberSeq.num(); //CHI32';// custTable.CustGroup ='020'; custTable.Currency ='BRL'; custTable.PaymTermId ='10DD'; custTable.PaymMode ='CHEQUE-01'; custTable.insert(DirPartyType::Organization, name); //DirParty /* Creates a new instance of the DirParty class from an address book entity that is represented by the custTable parameter. */ dirParty = DirParty::constructFromCommon(custTable); dirPartyPostalAddressView.LocationName ='HeadQuarters '; dirPartyPostalAddressView.City ='São Paulo'; dirPartyPostalAddressView.Street ='4th Avenue'; dirPartyPostalAddressView.StreetNumber ='18'; dirPartyPostalAddressView.CountryRegionId ='BRA'; dirPartyPostalAddressView.State ='SP'; // Fill address dirParty.createOrUpdatePostalAddress(dirPartyPostalAddressView); dirPartyContactInfo.LocationName ='SouthStreet Contact Phone'; dirPartyContactInfo.Locator ='551291165341'; dirPartyContactInfo.Type = LogisticsElectronicAddressMethodType::Phone; dirPartyContactInfo.IsPrimary = NoYes::Yes; // Fill Contacts dirParty.createOrUpdateContactInfo(dirPartyContactInfo); // Marks the end of transaction. ttsCommit; } catch(Exception::Error) { ttsAbort; // throwException::Error; } } }
Method Calling Sequences of Table in AX 2012
When you press CTR+N
inItValue()
When you change data in a Field
validateField() -> validateFieldValue() -> ModifiedField() -> ModifiedFieldValue()
When you close the table after entering some data
validateWrite() – > Insert() -> aosValidateInsert()
When you open the table which will contain some data
If table will contain 10 records this method is called 10 times
aosValidateRead()
When you Save the Record for the first time
validateWrite() ->Insert() – > aosValidateInsert()
When you modify the record and saving
validateWrite() -> update() – > aosValidateUpdate()
When you delete the record
validateDelete() -> delete() -> aosValidateDelete()
https://daxingwitheshant.blogspot.com/search/label/Table%20methods
Method Calling Sequences of Table in AX 2012
When you press CTR+N
inItValue()
When you change data in a Field
validateField() -> validateFieldValue() -> ModifiedField() -> ModifiedFieldValue()
When you close the table after entering some data
validateWrite() – > Insert() -> aosValidateInsert()
When you open the table which will contain some data
If table will contain 10 records this method is called 10 times
aosValidateRead()
When you Save the Record for the first time
validateWrite() ->Insert() – > aosValidateInsert()
When you modify the record and saving
validateWrite() -> update() – > aosValidateUpdate()
When you delete the record
validateDelete() -> delete() -> aosValidateDelete()
Form Method Calling Sequence in AX 2012
Form Method Calling Sequence in AX 2012
http://daxingwitheshant.blogspot.com/2015/04/form-method-calling-sequence-in-ax-2012.html
Form Method Calling Sequence in AX 2012
Form Method Calling Sequence in AX 2012
The sequence of Methods calls while opening the Form
Form — init ()
Form — Datasource — init ()
Form — run ()
Form — Datasource — execute Query ()
Form — Datasource — active ()
Sequence of Methods calls while closing the Form
Form — canClose ()
Form — close ()
Sequence of Methods calls while creating the record in the Form
Form — Datasource — create ()
Form — Datasource — initValue ()
Table — initValue ()
Form — Datasource — active ()
Sequence of Method calls while saving the record in the Form
Form — Datasource — ValidateWrite ()
Table — ValidateWrite ()
Form — Datasource — write ()
Table — insert ()
Sequence of Method calls while deleting the record in the Form
Form — Datasource — validatedelete ()
Table — validatedelete ()
Table — delete ()
Form — Datasource — active ()
Sequence of Methods calls while modifying the fields in the Form
Table — validateField ()
Table — modifiedField ()
DataEvent Handler in D365 F&O X++
Table Level:
// Table Level dataevent
[DataEventHandler(tableStr(CustTable), DataEventType::Inserting)]
publicstaticvoid CustTable_onInserting(Common sender, DataEventArgs e)
{
CustTable objcustTable = sender asCustTable;
//if(objcustTable.CustGroup == ’90’)
//{
// Global::error(“Created Customer is an Intercompany Cutomer and will be added to the Customer Group Other Customer %1”, objcustTable.AccountNum);
//}
//else
//{
objcustTable.CustGroup = ’30’;
Info(‘CustGroup has been set’);
//}
}
Field Level onValidatedField :
[DataEventHandler(tableStr(CustTable), DataEventType::ValidatedField)]
public static void CustTable_onValidatedField(Common sender, DataEventArgs e)
{
CustTable objcustTable = sender as CustTable;
if(strLen(objcustTable.AccountNum) > 5)
{
Global::error(“Lenth is exeed so please eneter the valid lenght under 5”);
objcustTable.AccountNum = “”;
}
}
______________________________—————————–
From dataSource Level:
[FormDataSourceEventHandler(formDataSourceStr(VendTable, VendTable), FormDataSourceEventType::InitValue)]
public static void VendTable_OnInitValue(FormDataSource sender, FormDataSourceEventArgs e)
{
FormRun formRun = sender.formRun();
Object hcmEmploymentLeave_ds = formRun.dataSource(formDataSourceStr(VendTable, VendTable)) as FormDataSource;
//Object hcmEmploymentLeave_ds = formRun.dataSource(formDataSourceStr(VendTable, DirPartyTable)) as FormDataSource;
VendTable vendObj = hcmEmploymentLeave_ds.cursor();
//DirPartyTable vendObj = hcmEmploymentLeave_ds.cursor();
vendObj.AccountNum = ‘GovindVendor’;
info(strFmt(“This is VendTable_OnInitValue functiion %1”, vendObj.AccountNum ));
}
[FormDataSourceEventHandler(formDataSourceStr(VendTable, DirPartyTable), FormDataSourceEventType::InitValue)]
publicstaticvoid DirPartyTable_OnInitValue(FormDataSource sender, FormDataSourceEventArgs e)
{
FormRun formRun = sender.formRun();
Object hcmEmploymentLeave_ds = formRun.dataSource(formDataSourceStr(VendTable, DirPartyTable)) asFormDataSource;
DirPartyTable vendObj = hcmEmploymentLeave_ds.cursor();
vendObj.NameAlias = ‘My Name is’;
}
___________________________________________
Field Level DataEvent
/// /// ///
///
///
[FormDataFieldEventHandler(formDataFieldStr(VendTable, VendTable, AccountNum), FormDataFieldEventType::Modified)]
public static void AccountNum_OnModified(FormDataObject sender, FormDataFieldEventArgs e)
{
}
// form’s field level
[FormDataFieldEventHandler(formDataFieldStr(VendTable, VendTable, AccountNum), FormDataFieldEventType::Modified)]
publicstaticvoid AccountNum_OnModified(FormDataObject sender, FormDataFieldEventArgs e)
{
FormDataSource ledgerJournalTrans_ds = sender.datasource();
VendTable objj = ledgerJournalTrans_ds.cursor();
objj.AccountNum = objj.AccountNum + ‘365’;
info(strFmt(‘This is a formal onModifiedMethod ‘, objj.AccountNum));
}
Full Code
class CustTable_EventHandlerInserting
{
[DataEventHandler(tableStr(CustTable), DataEventType::Inserting)]
public static void CustTable_onInserting(Common sender, DataEventArgs e)
{
CustTable objcustTable = sender as CustTable;
//if(objcustTable.CustGroup == ’90’)
//{
// Global::error(“Created Customer is an Intercompany Cutomer and will be added to the Customer Group Other Customer %1”, objcustTable.AccountNum);
//}
//else
//{
objcustTable.CustGroup = ’30’;
Info(‘CustGroup has been set’);
//}
}
[DataEventHandler(tableStr(CustTable), DataEventType::Inserted)]
publicstaticvoid CustTable_onInserted(Common sender, DataEventArgs e)
{
CustTable objcustTable = sender asCustTable;
Info( strFmt(‘when you click on the save button inseted with %1’, objcustTable.AccountNum));
}
[DataEventHandler(tableStr(CustTable), DataEventType::ValidatedField)]
publicstaticvoid CustTable_onValidatedField(Common sender, DataEventArgs e)
{
CustTable objcustTable = sender asCustTable;
if(strLen(objcustTable.AccountNum) > 5)
{
Global::error(“Lenth is exeed so please eneter the valid lenght under 5”);
objcustTable.AccountNum = “”;
}
}
// vendTable Form level
[FormDataSourceEventHandler(formDataSourceStr(VendTable, VendTable), FormDataSourceEventType::ValidatedWrite)]
publicstaticvoid VendTable_OnValidatedWrite(FormDataSource sender, FormDataSourceEventArgs e)
{
FormRun formRun = sender.formRun();
Object hcmEmploymentLeave_ds = formRun.dataSource(formDataSourceStr(VendTable, VendTable)) asFormDataSource;
VendTable vendObj = hcmEmploymentLeave_ds.cursor();
//Assigning value to the field
info(strFmt(“This is validated Write functiion %1”, vendObj.AccountNum ));
}
[FormDataSourceEventHandler(formDataSourceStr(VendTable, VendTable), FormDataSourceEventType::InitValue)]
publicstaticvoid VendTable_OnInitValue(FormDataSource sender, FormDataSourceEventArgs e)
{
FormRun formRun = sender.formRun();
Object hcmEmploymentLeave_ds = formRun.dataSource(formDataSourceStr(VendTable, VendTable)) asFormDataSource;
//Object hcmEmploymentLeave_ds = formRun.dataSource(formDataSourceStr(VendTable, DirPartyTable)) as FormDataSource;
VendTable vendObj = hcmEmploymentLeave_ds.cursor();
//DirPartyTable vendObj = hcmEmploymentLeave_ds.cursor();
vendObj.AccountNum = ‘GovindVendor’;
info(strFmt(“This is VendTable_OnInitValue functiion %1”, vendObj.AccountNum ));
}
[FormDataSourceEventHandler(formDataSourceStr(VendTable, DirPartyTable), FormDataSourceEventType::InitValue)]
publicstaticvoid DirPartyTable_OnInitValue(FormDataSource sender, FormDataSourceEventArgs e)
{
FormRun formRun = sender.formRun();
Object hcmEmploymentLeave_ds = formRun.dataSource(formDataSourceStr(VendTable, DirPartyTable)) asFormDataSource;
DirPartyTable vendObj = hcmEmploymentLeave_ds.cursor();
vendObj.NameAlias = ‘My Name is’;
}
}
Custom Batch Job – How to create custom batch job in dynamics 365 finance and operation
How to create a custom batch job in dynamics 365 finance and operation
https://www.youtube.com/watch?v=F2QPPMT0n1g&t=858s&ab_channel=SolutionsHub
public class YoutubeTutorial extends RunBaseBatch { public void run() { //Code to execute } //Needs to be set to true so class can be ran in a batch boolean canGoBatch() { return true; } //Stores parameters of the batch public container pack() { return conNull(); } //Returns the stored object for the batch to use public boolean unpack(container packedClass) { return true; } //Determines whether to run on server or client //True – Server; False – Client public boolean runsImpersonated() { return true; } }