Saturday, January 5, 2019

Error after clicking on “ Show all fields” in Dynamics AX

Recently i noticed that "show all fields" functionality is not working on Vendor Inter company form. After further investigation i came to know that this functionality is working on most of the form . However, for few forms it through below error.

I do some research and find that there is a bug in system in below method.

This is bug in system. Actually any form name can not be more than 40 char. but in our case '_ShowAllRecords_'+dictTable.name() is 55 char (InterCompanyTradingRelationSetupCustomer(40), _ShowAllRecords(15)) and hence system throw above error.

As work around I removed _ShowAllRecords and now this functionality is working for intercompany form.

Secondly there is also few KB in LCS that can be explored for permanent solution.

I hope above post help to resolve this issue.

Passing parameter between forms in Dynamics AX

How to: Pass Args from one form to another form in AX 2012

Passing parameter from one form to another is easy in AX and this concept help a lot during development and it can be achieved through Args class.
I am going to demonstrate below simple example to understand how Args works and what are the different options available in dynamics AX.

Form1: POCVehicleForm
Form2: POCInsuranceMaster  
And there is one common field vehicleId in both data source.
Task1: Pass record, string value and enum value from Form1 to Form2.
Task2: Filter data on form 2 according to the vehicle Id from form one.
Solution: Added one button on the POCVehicleForm to pass value on POCInsuranceMaster form.
Add below code snippet on "Insurance Master" clicked method on POCVehicleForm .
void clicked()
{
    MenuFunction        mf;
    Args                args;
    FormRun             formRun;
    ;
    //Initialise Args
    args= new Args();

    //Pass record
    args.record(POCVehicle);

    //Pass string value "Vehicle Id"
    args.parm(Grid_VehicleId.valueStr()); 
  
    //Pass Enam value
    args.parmEnum(VehicleType::Truck);

    //Pass enum type
    args.parmEnumType(enumNum(VehicleType));

    formRun=ClassFactory.formRunClass(args);
    formRun.init();
    formRun.run();
    formRun.wait();
}





Add below code snippet on POCInsurance’s init method.
public void init()
{
    POCVehicle              pocVehicle;
    Query                   query;
    ;

    super();
    // Get record buffer
    pocVehicle=element.args().record(); 

    // Validate if parameter is not null and record belong to right table  
    if(element.args() && element.args().record().TableId== tableNum(POCVehicle))
    {

    // Filter data according to the Vehicle ID    POCInsurenceMaster_ds.query().dataSourceName('POCInsurenceMaster').addRange(fieldNum(PO  CInsurenceMaster,vehicleID)).value(SysQuery::value(pocVehicle.VehicleId));

     // Show String and enum value                 
    info(strfmt("PARM:%1,PARMENUM:%2)", element.args().parm(),element.args().parmEnum()));  

}

Below is the result after clicking on Insurance Master button on POCVehicleForm

Below is the Args important methods:


Args Methods Details
record Get and set current or multiple record from caller table
caller Get or set the instance of the caller object
parm Get or sets string value including string field on caller form
parmEnum Get or set enum value
name Get and set the name of the application object to call
parmObject Get or set an instance of any object to pass on called object like any custom class 
parmEnumType Get or set enum name

Passing parameter from Form to Class through Args in Dynamics AX 2012


Friday, January 4, 2019

How to read excel and update record in AX2012 through X++ code


static void POCUpdatePurchaseDetails_JS(Args _args)
{
    SysExcelApplication     application;
    SysExcelWorkbooks       workbooks;
    SysExcelWorkbook        workbook;
    SysExcelWorksheets      worksheets;
    SysExcelWorksheet       worksheet;
    SysExcelCells           cells;
    COMVariantType          type;
    Dialog dialog = new     Dialog("Excel upload utility");
    dialogField             dialogFilename;
    int row;
    int                     totalUpdatedRecord = 0;
    FileName                filename;
    InventTable             inventTable;
    ItemId                  itemId;
    ItemGroup               itemGroup;
    InventTableModule       inventTableModule;

    ;
    application = SysExcelApplication::construct();
    workbooks = application.workbooks();
    dialogFilename = dialog.addField(extendedTypeStr(FilenameOpen),"@SYS53125");

    dialog.filenameLookupTitle("Update data from excel file");
    dialog.filenameLookupFilter(["@SYS28576",'*XLSX', "@SYS28576",'*XLS']);
    if (!dialog.run())
        return;
    filename = dialogFilename.value();
    try
    {
        workbooks.open(filename);
    }
    catch (Exception::Error)

    {
        throw error("File cannot be opened.");
    }
    workbook = workbooks.item(1);
    worksheets = workbook.worksheets();
    worksheet = worksheets.itemFromNum(1);
    cells = worksheet.cells();
    row=1;
    do
    {
        row++;
        itemId = cells.item(row, 1).value().bStr();

        ttsbegin;

        inventTable = InventTable::find(itemId,true);
        inventTableModule=InventTableModule::find(inventTable.ItemId,ModuleInventPurchSales::Purch,true);
        if (inventTable)
        {
            inventTableModule.Price=str2num(cells.item(row, 2).value().bStr());
            inventTableModule.PriceUnit=str2num(cells.item(row, 3).value().bStr());
            inventTableModule.update();
            totalUpdatedRecord++;
        }

        ttscommit;
        type = cells.item(row+1, 1).value().variantType();
    }
    while (type != COMVariantType::VT_EMPTY);
    application.quit();

    info(strFmt('Data updated, total record=%1 record',totalUpdatedRecord));

}


Thursday, January 3, 2019

Error while restarting AX 2012 service

Issue: The database Servername\ModelDatabase is not recognised as a model store

Below error occurred while restarting AX2012 service after database restore:
 

  
Event log error:
Object Server 01:The database Servername\ModelDatabase is not recognized as a model store
Object Server 01:  Fatal SQL condition during login. Error message: "[Microsoft][SQL Server Native Client 10.0][SQL Server]Login failed for user “User name”



Solution: 
1. This issue happen when service account do not have access on the database from where we took backup. So simply AOS component can be uninstalled and installed again which will fix the issue.
2. After database refresh add AX service account in database security section and provide proper permission which will fix the issue.
login. Error message: "[Microsoft][SQL Server Native Client 10.0][SQL Server]Login failed for user “User name”

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));
  
}

Monday, September 1, 2014

AX Interview Question

Hi friends, Before to dive in actual post i would like to thank to all my friends for your love and appriciation. I hope attached document will help to find out some good question and answer for interview. Happy DAXing!!!