Monday, December 31, 2018

D365 Finance and Operations

D365 Finance and Operations is the latest version of Microsoft Dynamics ERP. D365 Finance and Operations is a cloud based enterprise resource planning (ERP) service for enterprises and built on Microsoft Azure.

D365 Finance and Operations facilitates and support customer's unique requirement and also provide the flexibility to modify ERP system to align their requirement to support operation in more effective and efficient way without any changes in operation processes.

Moreover, D365FO provide better platform through ERP functionality to run constantly changing business in competitive and challenging environment without hassle of maintaining infrastructure and software.

Monday, December 24, 2018

Refresh Caller form data source in AX 2012

Refresh Caller form data source:
Parent Form: POCVehicleForm
Child Form: POCInsurenceMaster

Write below code snippet on click method of button on POCVehicleForm

void clicked()
{
    MenuFunction        mf;
    Args                        args;
    ;

    args= new Args();
    args.record(POCVehicle);

    mf=new MenuFunction(identifierStr(POCInsurenceMaster), MenuItemType::Display);
    mf.run(args);
}

Overwrite below method on POCInsurenceMaster:

 public void closeOk()
    {
        #Task
        FormRun formRun;
        super();
        // Buffer of calling form.
        formRun = element.args().caller();
        // Check if caller is form
        if(formRun)
        {
            formRun.task(#taskF5);
        }
    }

Open POCInsurenceMaster from POCVehicleForm and once update record and close child form then parent form will be refreshed.

Update multiple record through MultiSelectionHelper class in AX 2012

Main method of class:
public static void main(Args args)
{
    FormDataSource                      formDataSource;
    TableName                           tableName;
    FormRun                             caller = args.caller();
    MultiSelectionHelper                helper = MultiSelectionHelper::createFromCaller(caller);
;
    // Find correct form data source
    for (i = 1; i <= caller.dataSourceCount(); i++)
    {
        formDataSource = caller.dataSource(i);
        if (formDataSource.table() == tableNum(TableName))
        {
            break;
        }
    }
    //Create ranges for the selected records
    helper.createQueryRanges(formDataSource.queryBuildDataSource(), fieldStr(TableName, RecId));
    // Traverse the selected records
    tableName = helper.getFirst();
    ttsBegin;
   
    while(tableName)
    {
        // Logic placeholder-Start
       
        // Logic placeholder-End
        tableName = helper.getNext();    
    }
    ttsCommit;
}

Update multiple selected records on form in AX 2012 through Class and Passing parameter from Form to Class

Passing parameter through Args in AX is very easy important functionality. To demonstrate this i used one form and added one button to call class.
Below are the artefacts:

Table:pocVehicle
Class:POCVehicleMasterClass
ManuItem:POCVehicleMasterClass

Method on Form button click:
void clicked()
{

MenuFunction mf;
  //POCVehicle pocVehicle;

Args args=new Args();
;
args.record(pocVehicle);
mf= new MenuFunction(identifierStr(POCVehicleMasterClass), MenuItemType::Action);
mf.run(args);


Main Methods on Class POCVehicleMasterClass :


Public static void main(Args _args)

{
POCVehicle pocVehicle;

POCVehicleMasterClass myClass;

FormDataSource formdatasource;

Common common;
;

myClass= new POCVehicleMasterClass();

if(_args.record().TableId==tableNum(POCVehicle))

{
//Buffer selected records
common=_args.record();
//formdatasource=_args.record().dataSource();
//Records data source
formdatasource=common.dataSource();
//Passing parameter to class updateRecord method
myClass.UpdateRecord(formdatasource,_args);
}

}


Second method on the class:

Public void UpdateRecord(FormDataSource datasource, Args args)
{

POCVehicle pocvehicle;
FormDataSource formDataSource;
int recordCount, recorUpdated;
;

formDataSource= datasource;
//Count selected records
RecordCount= formDataSource.recordsMarked().lastIndex();
recorUpdated=0;

//Update all selected records
for(pocvehicle=formDataSource.getFirst(true)? formDataSource.getFirst(true): formDataSource.cursor() ; pocvehicle ;pocvehicle=formDataSource.getNext())

{
ttsBegin;
pocvehicle.Insurence= NoYes::No;
pocvehicle.update();
ttsCommit;
recorUpdated++;

}
//Refresh caller form datasource with same pointer

formDataSource.research(true);

info(strFmt('%1 records selected and %2 records updated ', RecordCount,recorUpdated));
  
}