hljs.configure({cssSelector: "code"}); hljs.highlightAll();

Tuesday, December 15, 2020

Unable to connect to the remote server at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync

 Problem:

Microsoft.WindowsAzure.Storage.StorageException: Unable to connect to the remote server ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it.

Solution:

1.Open Command Prompt as Administrator.

2.Go to C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator\.

3. Run the following command "AzureStorageEmulator.exe start".



D365FO: Method Calling Sequence of Data Entity

Method calling sequence of data entities while importing and exporting of data.

Import:
 Entity:
   - PostLoad
   - InitValue
   - ValidateField (depends on no of fields)
   - ValidateWrite
   - InitializeEntityDataSource
   - mapEntityToDataSource
   - mapDataSourceToEntity
   - insertEntityDataSource
   - persistEntity
   - Insert

Staging:
    PostLoad

Export:
Entity:
      PostLoad


Friday, November 27, 2020

Form Event handler methods in Dynamics 365 FO

FormDataSourceEventHandler:

[FormDataSourceEventHandler(formDataSourceStr(CustGroup, CustGroup), FormDataSourceEventType::Activated)]

    public static void CustGroup_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)

    {

        FormRun formRun                = sender.formRun();

        FormDesign formDesign = formRun.design();

        FormButtonControl TestButton = formDesign.controlname('TestButton');

        CustGroup CustGroup = formRun.dataSource().cursor();

        TestButton.enabled(CustGroup.Name != '' );

    }

FormEventHandler:

     [FormEventHandler(formStr(CustGroup), FormEventType::Closing)]

    public static void CustGroup_OnClosing(xFormRun sender, FormEventArgs e)

    {

       FormDataSource ecoResProduct_ds   =                    sender.dataSource(formDataSourceStr(CustGroup,CustGroup));

        CustGroup      custGroup = ecoResProduct_ds.cursor();

       //Write your logic here

    }

FormControlEventHandler:

    [FormControlEventHandler(formControlStr(CustGroup, TestButton),  FormControlEventType::clicked)]

    public static void clicked_OnModified(FormControl sender, FormControlEventArgs e)

    {

       custgroup  custgroup;

      custgroup = sender.formrun().datasource().cursor();

      //Write your Logic here

   } 

Thursday, October 29, 2020

Hiding General tab in Sysoperation framework in ax 2012

place this code in  your controller class

protected void dialogPostRun()

{

   sysOperationDialog sysOperationDialog;

   DialogTabPage batchTab;

   FormRun formRun;

   super();

   sysOperationDialog = this.dialog() as SysOperationDialog;

   formRun = sysOperationDialog.formRun();

   batchTab = sysOperationDialog.batchDialogTabPage();

   formRun.selectControl(batchTab.control());

}

Tuesday, September 29, 2020

create purchase order from Excel in AX using X++

 static void ImportPurchaseorder(Args _args)

{

    Dialog _dialog;

    DialogField _file;

    SysExcelApplication application;

    SysExcelWorkbooks workbooks;

    SysExcelWorkbook workbook;

    SysExcelWorksheets worksheets;

    SysExcelWorksheet worksheet;

    SysExcelCells cells;

    COMVariantType type;

    FileName filename;

    PurchTable purchTable;

    PurchLine purchline;

    NumberSeq numberSeq;

    InventDim InventDimloc;

    int  row = 1;

    CustAccount     custAccount,orderaccount,site,warehouse;

    CurrencyCode    currencyCode;

    ItemId          itemId;

    real            Quantity,Lineamount,Unitprice;

    str             unit;

    _dialog = new Dialog("Please select the file to load");

    _dialog.addText("Select file:");

    _file   = _dialog.addField(ExtendedTypeStr("FilenameOpen"));

    _dialog.run();

    if (_dialog.closedOK())

    {

    //info(_file.value() );

    application = SysExcelApplication::construct();

    workbooks = application.workbooks();

    filename =_file.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();

    do

    {

        row++;

        custAccount = cells.item(row, 1).value().bStr();

        orderaccount = cells.item(row, 2).value().bStr();

        currencyCode = cells.item(row, 3).value().bStr();

        itemId = cells.item(row, 4).value().bStr();

        site = any2str(cells.item(row, 5).value().bStr());

        warehouse = any2str(cells.item(row, 6).value().bStr());

        Quantity = cells.item(row, 7).value().double();

        unit = cells.item(row, 8).value().bStr();

        Unitprice = cells.item(row, 9).value().double();

        numberSeq =NumberSeq::newGetNum(purchparameters::numRefPurchId(),true);

        purchTable.initValue();

        purchTable.PurchId = numberSeq.num();

        purchTable.OrderAccount = custAccount;

        purchTable.InvoiceAccount =orderaccount ;

        purchTable.CurrencyCode = currencyCode;

        purchTable.LanguageId = currentUserLanguage();

        purchTable.initFromVendTable();

        if (purchTable.validateWrite())

        {

            purchTable.insert();

        }

        purchLine.PurchId = purchTable.PurchId;

        purchLine.ItemId = itemId ;

        purchLine.itemIdChanged();

        select InventDimId from inventDimLoc

        where inventDimLoc.InventLocationId== site

        && inventDimLoc.InventSiteId== warehouse;

        purchLine.InventDimId=inventDimLoc.InventDimId;

        purchLine.PurchQty = Quantity;

        purchLine.modifiedField(fieldNum(purchLine, PurchQty));

        purchLine.PurchUnit = unit;

        purchLine.modifiedField(fieldNum(purchLine, PurchPrice));

        purchLine.setPriceDiscChangePolicy(PriceDiscSystemSource::ManualEntry,fieldNum(purchLine, PurchPrice));

        purchLine.createLine(true, true, true, true, true, true);

        ttsBegin;

        purchLine.selectForUpdate(true);

        purchLine.PurchPrice = Unitprice ;

        purchLine.LineAmount = purchLine.PurchQty * purchLine.PurchPrice ;

        purchLine.update();

        ttscommit;

        type = cells.item(row+1, 1).value().variantType();

    }

    while (type != COMVariantType::VT_EMPTY);

    application.quit();

    info(strFmt("@DAR91",purchTable.PurchId));

}

}

Monday, September 28, 2020

XDS Framework in D365FO/AX 2012

 

XDS is used to restrict the data to the users based on their role. XDS replaces the Record level security framework in previous Microsoft Dynamics AX versions.

The security policies are applied on AOS and hence applied to any data retrieved from any client,whether in Rich, AIF web services or Enterprise portal.

Primary Table:

A primary table is used to restricts the data in the Constrained table.This table we will Specify in policy Query.

Constrained Table:

A constrained table is a table on which the filtering applied.  Based on the query range the data filterfrom constrained table.

Policy Query:

It will secure the data in constrained table define in the XDS.It is used to fetch the data from primary table and then it restricts the constrained table data.

Scenario:

As part of this tutorial, security policy will be applied to the Customer role, who can only view customers having financial dimension value (BusinessUnit,001).

 Here  I have joined the four tables to retrieve dimension values. The tables are DimensionAttributeValueSet, DimensionAttributeValueSetItem, DimensionAttributeValue and DimensionAttribute.

Steps:

1.Go to AOT Queries and Create a query and specify the datasources.

 Set dynamic property value to Yes.

 Go to dimensionAttributeValueSetItem  datasource ranges and set display value as “001”.

 Go to dimensionAttribute datasource ranges and set name value as “BusinessUnit”.

2.Go to Securities and create a new security policy.

Set the properties as shown in the below screen.






In context type property we will get  three options

·         Context string

 Defines a specific application context on which security policy will be enabled. It is also

called an application context. 

·         RoleName:

It is selected when the policy has to apply on a particular role.

·         RoleProperty:

It is used to define multiple roles for a single security policy.

Policy will be  applied only when the context string property of both Security policy and Security Role matches.

And  specify the constrained table under  security policy constrained table node.

Here I have added custtable  and vendtable.

3.Create a Role and specify it in security policy property.


Just go and check the result. You can only see customers who is having financial dimension values as BusinessUnit-001.

Note:

    Xds is not applied  to system administrator roles. 

Keep Learning!!

Sunday, August 30, 2020

Query Classes in AX 2012

 static void queryClasses(Args _args)

{


    date            dateFrom    = 01\01\2012 ;

    date            dateTo      = 31\01\2012 ;

    Query query;

    QueryBuildDataSource queryBuildDataSource;

    QueryBuildRange queryBuildRange,qbr;

    QueryBuildFieldList  qbfl       ;

    QueryRun queryRun;

    CustTrans custTrans;

    ;

    query = new Query();

    queryBuildDataSource = query.addDataSource(tablenum(CustTrans));

    queryBuildRange = queryBuildDataSource.addRange(fieldnum(CustTrans,AccountNum));

    qbr = queryBuildDataSource.addRange(fieldNum(CustTrans,TransDate));

    //queryBuildRange.value("Us-010,us-020  ");

    qbr.value(SysQuery::range(dateFrom, dateTo));

    queryBuildDataSource.addSortField(fieldNum(CustTrans,AccountNum));

    //queryBuildDataSource.addSortField(fieldNum(CustTrans,Invoice));

    //Greater than or less than values passing

   // queryBuildRange.value('us-010..us-020');

    //passing like operator 

   // queryBuildRange.value('*Us*');

    //not like

    queryBuildRange.value('!*Us*');

    queryBuildDataSource.addSelectionField(fieldnum(CustTrans,RecId),SelectionField::Count);

    queryBuildDataSource.orderMode(OrderMode::GroupBy);

    info(queryBuildDataSource.toString());

    queryRun = new QueryRun(query);

    while (queryRun.next())

    {

    custTrans = queryRun.get(tablenum(CustTrans));


    info (strfmt(" Customer Account  :%1 Group : %2",custTrans.AccountNum,custTrans.RecId ));


    }

}

Friday, August 28, 2020

AOT Maps in Ax 2012

 The fields of the maps are basically use to map fields of one or more tables.By the help of a maps we can   access   the fields of one or more tables with different names.

Steps For Creating Maps:

  For implementation i have created two tables named DaxSalesTable and DaxProductsTable you can see  in          below  image.

                         

    in both the tables i have similar fields.

    After that i created a Map 

    AOT >> DataDictionary >> Maps and Right click and create a Map

    then add the fields to map here i have added three fields.As you can see in below image

                            

     

      Next,Under your newly created map you can find mappings node 

      Create mapping  and Set the property mapping table

            

   Here i have mapped DaxProductsTable  and then i have mapped the fields as you can see in below image

     

  Now I have created a job on which I will map a table on this map and than use it.

  static void Job3(Args _args)

{

    DaxMapTest          test; //map declaration

    // tables

    DaxSalesTable       daxSalesTable;

    DaxProductsTable    daxProductsTable;

    // Assigning values to the map 

    test.productnumber = "DAX-001";

    test.ProductName   = "Jaipal Jadav";

    info(strFmt("Map AccountNum : %1",test.productnumber));

    // Now here  setting accountnum field to daxProductsTable field

    test = daxProductsTable;

    test.productnumber = "DAX-002";

    test.ProductName   = "Srikanth Jadav";

    info(strFmt("Salestable AccountNum : %1",test.productnumber));

    //Now here  setting accountnum field to daxSalesTable field

    test = daxSalesTable;

    test.productnumber = "DAX-003";

    test.ProductName   = "Akhil Jadav";

    info(strFmt("Producttable AccountNum :%1",test.productnumber));

    

}

 Result:

  

           

Thursday, August 20, 2020

X++ Code to Create Purchase Order In Ax 2012

 Static void Purchaseorder()

{

PurchTable purchTable;

PurchLine purchline;

NumberSeq numberSeq;

InventDim InventDimloc;

numberSeq =NumberSeq::newGetNum(purchparameters::numRefPurchId(),true);

purchTable.initValue();

purchTable.PurchId = numberSeq.num();

purchTable.OrderAccount = "US-101";

purchTable.InvoiceAccount ="US-101" ;

purchTable.CurrencyCode = "USD";

purchTable.LanguageId = currentUserLanguage();

purchTable.initFromVendTable();

if (purchTable.validateWrite())

{

purchTable.insert();

}

//purchase order lines

purchLine.PurchId = purchTable.PurchId;

purchLine.ItemId = "D0001" ;

purchLine.itemIdChanged();

select InventDimId from inventDimLoc

where inventDimLoc.InventLocationId=="13"

&& inventDimLoc.InventSiteId=="1";

purchLine.InventDimId=inventDimLoc.InventDimId;

purchLine.PurchQty = 5.0;

purchLine.modifiedField(fieldNum(purchLine, PurchQty));

purchLine.PurchUnit = "EA";

//purchLine.PurchPrice = RealEdit1.realValue();

purchLine.modifiedField(fieldNum(purchLine, PurchPrice));

purchLine.setPriceDiscChangePolicy(PriceDiscSystemSource::ManualEntry,fieldNum(purchLine, PurchPrice));

purchLine.createLine(true, true, true, true, true, true);


ttsBegin;

purchLine.selectForUpdate(true);

// purchLine.InventDimId=inventDimLoc.InventDimId;

purchLine.PurchPrice = 500.0;

purchLine.LineAmount = purchLine.PurchQty * purchLine.PurchPrice ;

purchLine.update();

ttscommit;


info(strFmt("@DAR91",purchTable.PurchId));



}

Wednesday, August 19, 2020

General Journal Creation and Posting in AX 2012 Using X++

 static void GeneralJournalCreate(Args _args)

{

    //class for journal header creation

    AxLedgerJournalTable   axLedgerJournalTable ; 

    //class for journal lines creation

    AxLedgerJournalTrans   axLedgerJournalTrans;  

    container              accPattern;    

    container              offSetPattern;

    // class for journal  posting

    ledgerJournalCheckPost ledgerJournalCheckPost; 

    axLedgerJournalTable = new AxLedgerJournalTable();

    axLedgerJournalTrans = new AxLedgerJournalTrans();

    // Journal Header creation

    axLedgerJournalTable.parmJournalName("GenJrn");

    axLedgerJournalTable.save();     

    // Journal lines Creation

    axLedgerJournalTrans.parmJournalNum(axLedgerJournalTable.ledgerJournalTable().JournalNum);

    axLedgerJournalTrans.parmTransDate(systemDateGet());

    axLedgerJournalTrans.parmAmountCurDebit(300);

    //axLedgerJournalTrans.parmAmountCurcredit(300);

    axLedgerJournalTrans.parmAccountType(LedgerJournalACType::Ledger);

    // 2-indicates no of financial dimension values

    // 110110- main account id and dispaly name

    accPattern = ['110110','110110',2,'BusinessUnit',"001","Department","022"];

    axLedgerJournalTrans.parmLedgerDimension(AxdDimensionUtil::getLedgerAccountId(accPattern));

    offSetPattern = ['112140',"112140",2,'BusinessUnit','003',"Department","024"];

    axLedgerJournalTrans.parmOffsetLedgerDimension(AxdDimensionUtil::getLedgerAccountId( offSetPattern));

    axLedgerJournalTrans.save();

    info(strFmt("Journal %1 created", axLedgerJournalTable.ledgerJournalTable().JournalNum));

    // Journal Posting

    ledgerJournalCheckPost = ledgerJournalCheckPost::newLedgerJournalTable(axLedgerJournalTable.ledgerJournalTable(),NoYes::Yes);

    ledgerJournalCheckPost.run();

    info(strFmt("Journal No. %1.", axLedgerJournalTable.ledgerJournalTable().JournalNum));

}