Showing posts with label AOT. Show all posts
Showing posts with label AOT. Show all posts

July 06, 2023

Synchronize the table from Visual studio Project - D365 FO

From Visual studio project node, we can perform database synchronization either on a required table (or) on few tables bases on our requirement.

This could be very useful during on-premises environments package deployments because can drastically reduce the downtime.

In fact you can only synchronize the tables that you have actually modified rather than perform an entire synchronization

To perform a single table db sync simply Right click on project >>synchronize table. 

April 21, 2023

X++ code to get List of tables and fields and methods available on table

We might get some scenarios to get the list of objects or a list of elements available in a particular object in X++. Here is a sample piece of code to retrieve the details about the table object.

Whenever we try to get the metadata of an object (Tables, Table fields, 

table methods) we should keep in mind to use the below namespace in our code.

using Microsoft.Dynamics.AX.Metadata.MetaModel;

To get list of tables

using Microsoft.Dynamics.AX.Metadata.MetaModel;
public class TableNamesList
{
    public static void getTableNames()
    {
       var tables = Microsoft.Dynamics.Ax.Xpp.MetadataSupport::GetAllTables();
        var tablesEnumr = tables.GetEnumerator();
        while (tablesEnumr.MoveNext())
        {
            info(strfmt("%1", axTable.Name));
        }
    }
}


To get list of Fields from a table

public static void getFieldNames()
    {
        AxTable table =     Microsoft.Dynamics.Ax.Xpp.MetadataSupport::GetTable(tableId2Name(tablenum(SalesTable)));
       var fields = table.Fields;
        var fieldEnumerator = fields.GetEnumerator();
        while (fieldEnumerator.MoveNext())
        {
            info(strfmt("%1", field.Name));
        }
    }


To get list of methods available on a table

public static void getMethodNames()
    {
        AxTable table = Microsoft.Dynamics.Ax.Xpp.MetadataSupport::GetTable(tableId2Name(tablenum(SalesTable)));
        var methods = table.Methods;
        var methodEnumerator = methods.GetEnumerator();
        while (methodEnumerator.MoveNext())
        {
            AxMethod method = methodEnumerator.Current;
            if(method.IsDisplay)
            {
                info(strfmt("Display method : %1", method.Name));
            }
            else
            {
                info(strfmt("Normal method : %1", method.Name));
            }
        }
    }

Similar to the above code, we can use the metadata .dll in X++ 

to get all the objects and its related details available in AOT 

March 15, 2023

To Get & Set Unbound Control Values from a Form Extension, perform action on Controls

Example::

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

public static void CustTable_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)

{

    CustTable           custTable     = sender.cursor(); //selected record

    FormDataSource      custTable_ds  = sender.formRun().dataSource("CustTable"); //DataSource form CustTable

    FormRun             element       = sender.formRun(); //form element

    FormControl         myNewButton   = element.design(0).controlName("MyNewButton"); //New button on the form


    FormStringControl         strResult;

    FormRealControl realResult;

    FormIntControl         intResult;

    FormDateControl dateResult;

    FormComboBoxControl comboResult;


    //To Get DataSource Current Record of a Field

    custTable.AccountNum = XXX.valueStr();

    //Str

    strResult = element.design().control(element.controlId("strResult"));

    //Set

    strResult.text("this is what it should say");

    //Get

    strResult.valueStr();


    //Real

    realResult = element.design().control(element.controlId("realResult"));

    //Set

    realResult.realValue(50.05);

    //Get

    realResult.value();


    //Integer

    intResult = element.design().control(element.controlId("intResult"));

    //Set

    intResult.value(50);

    //Get

    intResult.value();


     //Date

     dateResult = element.design().control(element.controlId("dateResult"));

     //Set

     dateResult.dateValue(today());

     //Get

     dateResult.dateValue();


     //Date

     comboResult = element.design().control(element.controlId("comboResult"));

     //Set

     comboResult.selection(1);

     //Get

    comboResult.valueStr(); //Convert to Enum to Str

    myNewButton.enabled(false); //Here you do your code to enabled or disabled the button

}