Scenario:

Normally when we open form for the first time in Dynamics AX, it will take sometimes to compilte and cache into AOS. That’s why at second time always faster. If we often restart AOS, how can we keep performance ?

Solution:

After restart AOS we can let some scripts run to open up some often used forms then cache to AOS, then close those forms.

Here is the code

static void WarmupRF(Args _args)

{
    UtilElements e;
    TreeNode treeNode;
    FormRun formRun;

    Args args = new Args();

    while select e
        where e.utilLevel  == UtilEntryLevel::var    //<-- specify layer here
        &&    e.recordType == UtilElementType::Form  //<-- and only forms
        &&    e.name like "nameofformPrefix"

        {
            try
            {
                treeNode = xUtilElements::getNodeInTree(xUtilElements::parentElement(e));
                args.name(treeNode.AOTname());
                formRun = ClassFactory.formRunClass(args);
                formRun.init();
                //formRun.run();   //<-- No need to run the form, but sometimes it can load the data
                formRun.close();
            }
            catch
            {
                Infolog.clear();
                continue;
            }
        }
}

To make something as the LIKE operator in a query, just assign a value to the QueryRange including a wildcard.

static void QueryBuildRange_Sample(Args _args)
{
    Query                       query = new Query();
    QueryRun                    queryRun;
    QueryBuildDataSource        qbds;
    QueryBuildRange             queryRange;   
    CustTable                   custTable;
    
    qbds.addDataSource(tableNum(CustTable));
    
    queryRange = qbds.addRange(fieldNum(CustTable, AccountNum));
    
    queryRange.value("axd*");
    
    queryRun = new QueryRun(query);
    
    while(queryRun.next())
    {
        custTable = queryRun.get(tableNum(CustTable));
        print custTable.AccountNum;
    }
    pause;
}

Beside modify metadata on form properties, as best practice we can use code like below to assign default value for combobox.

  • You can use this code in the form’s init method after super():
ComboBoxName.selection(ComboBoxName::DefaultValue);
  • If this is a table field we should you best practice overriding the initValue method in the table:
this.ComboBoxName = ComboBoxName::DefaultValue;
  • Override initValue in the form’s datasource only if it should be a specific behaviour in this form only.

  1. Open Microsoft SQL Server Management Studio.

  2. Connect to the server where in the DB you want to rename is located.

  3. Modify the following script and run it

-- Replace all MyDBs with the name of the DB you want to change its name
USE [MyDB];
-- Changing Physical names and paths
-- Replace all NewMyDB with the new name you want to set for the DB
-- Replace 'C:...NewMyDB.mdf' with full path of new DB file to be used
ALTER DATABASE MyDB MODIFY FILE (NAME = ' MyDB ', FILENAME = 'C:...NewMyDB.mdf');
-- Replace 'C:...NewMyDB_log.ldf' with full path of new DB log file to be used
ALTER DATABASE MyDB MODIFY FILE (NAME = ' MyDB _log', FILENAME = 'C:...NewMyDB_log.ldf');
-- Changing logical names
ALTER DATABASE MyDB MODIFY FILE (NAME = MyDB, NEWNAME = NewMyDB);
ALTER DATABASE MyDB MODIFY FILE (NAME = MyDB _log, NEWNAME = NewMyDB_log);
  1. Right click on the DB and select Tasks>Take Offline

  2. Go to the location that MDF and LDF files are located and rename them exactly as you specified in first two alter commands. If you changed the folder path, then you need to move them there.

  3. Go back to Microsoft SQL Server Management Studio and right click on the DB and select Tasks>Bring Online.

When I try to install Web Services on IIS for Retails POS Component, and I got the problem.

This scenario shouldn’t be common in a production environment, but, it is indeed quite common in a VM machine (I’m using virtual machine Hyper-V on Windows 8.1)

Error:

Exception has been thrown by the target of an invocation

So, the problem is relate to thee AOS Service account, which by default is usually NT AUTHORITYNETWORK SERVICE account.

but because of we are running on a Domain Controller Server, we should use any specific Domain account created just for running AOS services, then you’ll success installing Web Services on IIS.

Now please restart services and try again.

Thank you for reading