DAXSPOT

Tuesday, November 15, 2022

Accessing Data of other companies/Legal entities using X++

Hi,

In Microsoft Dynamics AX/D365 Finance and operation, users can setup multiple legal entities. By default in Microsoft Dynamics AX/D365 FO, all tables store data per company unless SaveDataPerCompany property is not changed to NO. By default value of property SaveDataPerCompany  = Yes.

Using crossCompany & changeCompany keyword, you can construct a query to retrieve all records, regardless of the company you are currently logged into. You can fetch the all the company records using keyword - crossCompany and function – changeCompany.


Change-Company:

static void main()

{

  CustTable custTable;

  changeCompany('INMF') 

  {

    custTable = null;

    while select custTable

    {

       //custTable of company 'INMF'.

    }

  }

}


Cross-Company:

static void main()

{

  CustTable custTable;

  while select crosscompany custTable

  {

      //custTable of all the companies

  }

}


Thank you,

Saturday, November 12, 2022

D365F&O / AX7 URL parameters

Hi All,

This post is regarding different type of D365F&O URL parameters.


1. Calling a Display – MenuItem directly via the ''mi'' Parameter

With the ''mi'' parameter you can call a (Display) MenuItem directly. The example shows how to call the ''SalesTableListPage'' directly.

Call: ?cmp=[Company]&mi=[MenuItemName]

Example: MenuItemName -> SalesTableListPage


2. Open a Form via an URL Parameter

If you want to call a Form directly, use the parameter "f".

Call: ?cmp=[Company]&f=[FormName]

Example: MenuItemName -> ProdParameters


3. See your Data in the Built-In Table Browser

The very convenient built-in table browser can be called from the address bar as well. Just use the "mi" parameter from above and add the parameter "tablename", afterwards add the name of the table you want to see.

Call: ?cmp=[Company]&mi=SysTableBrowser&tablename=[TableName]

Example: TableName -> SalesTable


4. Run a Class directly from your Browser

You can also call a runnable class. To do so, add the "SysClassRunner" menu item and the parameter "cls" with the class you want to call.

Call: ?cmp=[Company]&mi=SysClassRunner&cls=[SysClassRunnerExample]


class SysClassRunnerExample

{        

    /// <summary>

    /// Runs the class with the specified arguments.

    /// </summary>

    /// <param name = "_args">The specified arguments.</param>

    public static void main(Args _args)

    {        

        info("From Classrunner!");

    }

}


5. Change the language on the fly

Changing the language is also an option that we can change from the address bar, just add the parameter "lng" and pass the language you want to change AX to.

Call: ?cmp=[Company]&lng=[en-us]


Thank you

Confirmation dialog box/pop up box, X++

Hello,


Below code will help you to show a pop up confirmation dialog.  


boolean    confirmButton;

confirmButton = Box::confirm("Are you sure want to confirm?", "Confirmation", "Once Confirmed, record can not be edited!");

if(confirmButton == true)

{

     info("Confirmed");

}

else

{

    info("Not Confirmed");

}


Thank you,

Tuesday, November 8, 2022

Calculate no of months between two dates, X++ Updated

Hello,

Recently I got a small problem to calculate no of months between two dates.

Dynamics Ax 2012 provides a default function which calculates no of intervals between two dates based on enumeration.


Function looks like:

intvNo(date input_date, date ref_date, int func)


You can use it as;

noOfIntervals = intvNo(refDate, inputDate, intvScale::Month);

 

intvScale enumeration have two values for months

 1. Month

 2. YearMonth


If we provide the intvScale::Month then X++ ignores the year and assumes that month is calculated within one year.

If we provide the intvScale::YearMonth then X++ calculate the number of months between different years. Consider following example:

static void NumberofMonthsbetweenTwodates(Args _args)

{

date inputDate = str2Date("1/1/2007", 213);

date refDate = str2Date("3/1/2009", 213);

int noOfMonths, noOfMonthsBetweenYears;

;

noOfMonths = intvNo(refDate, inputDate, intvScale::Month);

noOfMonthsBetweenYears = intvNo(refDate, inputDate, intvScale::YearMonth);

//noOfMonths= intvNo(firstdate,seconddate,IntvScale::Month);

print("noOfMonths  :"+int2str(noOfMonths) + "  ,noOfMonthsBetweenYears :"+int2str(noOfMonthsBetweenYears));

}

Info box will be return like:

noOfMonths  :2  ,noOfMonthsBetweenYears  :26

-----------------------------------------------------------------------------------------------

Some cases above code did not works then used following:

 InfAdjValidation_MX::monthDifference(FromDate _fromDate, ToDate _toDate)


Example is as follow.

FromDate _fromDate = mkDate(1,1,2018);

ToDate _toDate =mkDate(31,1,2018);

info(int2str( InfAdjValidation_MX::monthDifference( fromDate, toDate)));


Thank you,

Saturday, November 5, 2022

Clear value of all the controls in form, D365FO - X++

Hello,


Below code sample will help to clear value of all the controls in form. Code tested in D365FO X++.


   void clearFormControls(Object o)

    {

        FormBuildControl    formBuildControl;

        FormStringControl   formStringControl;

        FormInt64Control    formInt64Control ;

        FormIntControl      formIntControl ;

        FormRealControl     formRealControl;

        FormTimeControl     formTimeControl;

        FormCheckBoxControl formCheckBoxControl;

        FormDateControl     formDateControl;

        Date                emptyDate;

        int                 i;

        ;

        for (i=1;i<=o.controlCount(); i++)

        {

            formBuildControl = o.controlNum(i);                                       

            switch (ClassId2Name(classIdGet( element.control(formBuildControl.id()))))

            {

                case 'FormStringControl':

                    formStringControl = element.control(formBuildControl.id());

                    formStringControl.text('');

                    break;

                case 'FormIntControl':

                    formIntControl = element.control(formBuildControl.id());

                    formIntControl.value(0);

                    break;

                case 'FormInt64Control':

                    formInt64Control = element.control(formBuildControl.id());

                    formInt64Control.value(0);

                    break;

                case 'FormRealControl':

                    formRealControl = element.control(formBuildControl.id());

                    formRealControl.realValue(0);

                    break;

                case 'FormTimeControl':

                    formTimeControl = element.control(formBuildControl.id());

                    formTimeControl.value(0);

                    break;

                case 'FormCheckBoxControl':

                    formCheckBoxControl = element.control(formBuildControl.id());

                    formCheckBoxControl.value(0);

                    break;

                case 'FormDateControl':

                    formDateControl = element.control(formBuildControl.id());

                    formDateControl.dateValue(emptyDate);

                    break;

            }

            if (formBuildControl.isContainer())

                clearFormControls(formBuildControl);

        }

    }

How to execute SQL directly form Dynamics AX X++

How to execute Sql directly form Dynamics AX X++ Reference by : alirazazaidi Dynamics Ax provide many other ways to communicate with databas...