Thursday, November 9, 2017

How to fetch all the tables associated with a configuration key AX 2012

To fetch all the  tables associated with a particular configuration key we can use below code

static void FindTablesFromConfigKey(Args _args)
{
    // The name of the configuration key to be specified here
    str                     configKeyName   = "Prod";
    Dictionary              dictionary      = new Dictionary();
    ConfigurationKeyId      configKeyId     = dictionary.configurationKeyName2Id(configKeyName);
    TableId                 tableId;
    DictConfigurationKey    dictConfigurationKey;
    DictTable               dictTable;
    container               keyIds;
    int                     i;
    ;

    if (configKeyId)
    {
        // Find all children of the specified configuration key
        for (i = dictionary.configurationKeyNext(0); i; i = dictionary.configurationKeyNext(i))
        {
            dictConfigurationKey = new DictConfigurationKey(i);

            while (dictConfigurationKey.parentConfigurationKeyId())
                dictConfigurationKey = new DictConfigurationKey(dictConfigurationKey.parentConfigurationKeyId());

            if (dictConfigurationKey.id() == configKeyId)
                keyIds += i;
        }

        // Find all tables that have an appropriate configuration key
        i = 0;
        for (tableId = dictionary.tableNext(0);tableId;tableId = dictionary.tableNext(tableId))
        {
            dictTable = new DictTable(tableId);
            if (!dictTable.isMap() && !dictTable.isTmp() && !dictTable.isView())
            {
                if (confind(keyIds, dictTable.configurationKeyId()))
                {
                    i++;
                    info(dictTable.name());
                }
            }
        }
    }

    info(strfmt("%1 tables have configuration key '%2'", i, configKeyName));
}

You can use following configuration keys in the job:
LedgerBasic : General ledger
Bank : Bank
SysAdmin : Administration
LogisticsAdvanced : Logistics
LogisticsBasic : Trade
ProjBasic : Project
QuotationBasic : Quotations
AIF : Application Integration Framework
Currency : Currency
ReportingServices : Reporting Services
COSBaseModule : Cost accounting
Asset : Fixed assets
PBA_ProductBuilder : Product Builder
Req : Master planning
smmOutlook : Microsoft Office Outlook synchronisation
LedgerAdvanced : General ledger - advanced
Prod : Production Series I
WrkCtr : Resources
ProdRouting : Production Series II
SysDevelopmentXPP : X++ development
ProdShop : Production Series III
SMAManagement : Service management
SmmCRM : CRM Series
Event : Event
TradeAgreements : Trade agreements
AIFWebService : Application Integration Framework Web Services
Trv : Expense management
TradeInterCompany : Intercompany
SysDevelopmentMorphX : Development
ProjAdvanced : Project - advanced
WMSBasic : Warehouse Management I
WMSAdvanced : Warehouse Management II
KMBSC : Balanced Scorecard
EP : Enterprise Portal
HRMAdministration : Human Resource I
RFID : RFID
SysDatabaseLog : Database log
CSS : Customer Self-Service
SmmSM : Sales management
BankElectronicBanking : Electronic Banking
ESS : Employee Self-Service
BAS : Business analysis
PurchReq : Purchase Requisition
InventQualityManagement : Quality management
COSPlanCostCalc : Flexible Budgeting
SMASubscription : Subscription
JmgPayroll : Shop Floor Control - Pay generation
HRMCollaborative : Human Resource III
CRSECountry : Country/Regional specific features
JmgJob : Shop Floor Control - Job registration
SIG : Electronic signature
LedgerAdvanced2 : General ledger - advanced II
HRMManagement : Human Resource II
KMBPM : Business Process Management
KMQuestionnaireBasic : Questionnaire I
Jmg : Shop Floor Control
SmmTM : Telemarketing
SmmMA : Marketing automation
KMQuestionnaireAdvanced : Questionnaire II

Database logging using X++ in AX 2012


Use below code to add tables into database logging using X++

The code below will add all the fields of the specific table for database logging. Just replace InventItemSalesSetup with the table you want to use for database logging. You can also put the code in a loop to select group of tables.

static void setDBLogOnTable(Args _args)
{
    TableId tableId = tableNum(InventItemSalesSetup);
    DatabaseLog log;
    SysDictTable dictT = new SysDictTable(tableId);
    SysDictField dictF;
    Set fields;
    SetEnumerator   se;


    log.logType = DatabaseLogType::Update;
    log.logTable = tableId;
    fields = dictT.fields(false,false,true);
    se = fields.getEnumerator();
    while (se.moveNext())
    {
        dictF = se.current();

        log.logField = dictF.id();
        log.insert();
        info(strFmt("Adding field %1", dictF.name()));
    }
    SysFlushDatabaselogSetup::main();
}

Sunday, September 10, 2017

Deleting model files in AX 7





Although it is not recommended to delete the model files in AX 7 however there is a way to delete the model files if you are in development environment or learning AX 7. Just follow below path to delete the model files in AX 7.


1.       You need to stop AOS service by going into IIS manager.




2.       Open Command Prompt and change directory to path C:\AOSService\PackagesLocalDirectory\Bin
To check your packages local directory you can also go to IIS Manager and right click and select explore.



3.       Type the below line and press enter
C:\AOSService\PackagesLocalDirectory\Bin>ModelUtil.exe -delete -metadatastorepath=<Path to package directory> -modelname=<Model Name>

Usage:
C:\AOSService\PackagesLocalDirectory\Bin>ModelUtil.exe -delete -metadatastorepath="C:\AOSService\PackagesLocalDirectory" -modelname="Application suite VAR model"

4.       After deletion of the model you need to delete the package as well.
Go to C:\AOSService\PackagesLocalDirectory and delete the folder with the same name as your model.


5.       Just start AOS service from IIS manager and sync the DB.




Wednesday, September 6, 2017

Tutorial example for modifying Records and Infolog in tables in Dynamics 365 for Operations (AX 7)



To manipulate records in Dynamics 365 for operations we need to follow the below steps:

1. Open visual studio 2015, and create a new Operations Project of type Dynamics 365 for        
        Operations


2. Create a new  Model Test_Model if a model does not exists by clicking on Dynamics 365 in VS 
        menu

3. Check the project properties and make sure you have the setup as below and click apply.
-          Model property should reflect the correct model name
-          Startup Object property should be updated with the new runnable class which we will create in steps below.
1
4. Create a new class by right clicking on the project name ->add->NewItem
On the left page under operations artifacts, select code
On the right select Runnable Class and give a name for the class.


5. Write a simple X++ code to fetch data from BankAccountTable in AX and rebuild the project and click on Run


6. When running you might get an error saying “To run you must set a startup object (Such as a class, form, a menu item).Set this in the Startup project.”

This is because we have not mentioned the correct object name to run from a project, so we need to change this.
Go to Project properties and check if the ‘startup object’ is the name of the job you are trying to run.


7. When running an infolog in Dynamics 365 for operations, AX will open the client page in web browser and the data will be displayed  on the ribbon as shown in below screenshot (Bank Accou). 
- If the data is not displayed correctly, then please check the Company at the top right is the one where the data is.