Saturday, February 23, 2019

Frequently used functions in D365 operations

Below listed are some frequently used functions in AX 2012, AX 2012 R2/R3, Dynamics 365 operations

1) Print text using label ids.
SysLabel::labelId2String2(literalStr("@DPL1228"))

2)

The clocks on the client and server machines are skewed.

The clocks on the client and server machines are skewed. error reports showing label IDs instead of text.

There was issue after restarting DAX servers, where Microsoft SQL Server Reporting Services (SSRS) reports were showing label IDs instead of text. 

Reviewed event Viewer and looked at Windows Logs > Application to see any related errors. The error was as:

AXRDCE The AXRDCE extension caught an unexpected exception for report CustBasedata.Report.
The error message was:
A call to the Microsoft Dynamics AX SRSFrameworkService service failed. The clocks on the client and server machines are skewed.

Also, while running reports from DAX error was "The clocks on the client and server machines are skewed."

Search results online showed that there was an issue with time synchronization.

To resolve this error, execute command [net time /set /yes] and restarted SQL Server Reporting Services service.

Dynamics ax 2012 Id Conflicts

This content is re-blog of following two posts, through that i got the required info and fixed my issue.

So what is Conflicts ?
If a table ID or field ID is changed in Dynamics AX, data are lost during synchronization, because the table with the old ID (and containing data) is dropped at the beginning and then a new table is created with the same structure but a different ID. The same is valid analogically for table fields.
The data loss can be prevented in several ways (e.g. by data export and re-import), but one solution is really simple and painless. Realize how the situation looks in AX after the ID change (e.g. after installation of a layer with different IDs) but before the database synchronization:
Where Ids are stored in AX ?
You can identify all changed IDs by comparing values in AOT with values in SqlDictionary. And the update of SqlDictionary to the new ID can prevent the regeneration of database objects during synchronization.
ReleaseUpdateDB::changeTableId method is used to updated the SQLDictionary table it takes new and old table id and table name to update the record.
 //Updates table ID in SqlDictionary  
       if (ReleaseUpdateDB::changeTableId(  
         sqlDictionaryTable.tabId,  
         dictTable.id(),  
         dictTable.name()))  
       {  
         info(strFmt("Table ID changed (%1 -> %2)", sqlDictionaryTable.tabId, dictTable.id()));  
       }  
Sometime there is also the need of updating the table id and reflect in the metadata.
There is a Table with name “ModelElement” in AX model database. In this table we have few important fields as, it is important for us to understand these fields.
1. ElementType : this field contains type  ID of data object like for table fields its value will be 42 and for tables it will be 44.
2. AxId : this field contains actual object ID value which create conflicts among environments. We have to change this field value, e-g for AccountNum field of CustTable it could be as 1.
3. ParentId : this field contains parent object ID, like ID of the table, whose field we are looking at, e-g for AccountNum field of CustTable it could be as 77, which is table ID for CustTable.
I have build this query to check the table ids using sql.
 // this query can be used to read the current table id from model db  
 SELECT ELEMENTHANDLE, ROOTHANDLE, NAME, AXID, ORIGIN FROM MODELELEMENT   
 JOIN ELEMENTTYPES ON MODELELEMENT.ELEMENTTYPE = ELEMENTTYPES.ELEMENTTYPE  
 WHERE NAME IN ('legCustTableLegacy', 'legACCCreditLimitLevelLine', 'legAccountsParameterSetup', 'legAXEnums') AND ELEMENTTYPENAME IN ('TABLE')  
 
//This query can update the table id and reflect in meta data.  
 Update M  
 SET m.AxId = 105871  
 FROM MODELELEMENT as M  
 JOIN ELEMENTTYPES ON M.ELEMENTTYPE = ELEMENTTYPES.ELEMENTTYPE  
 WHERE NAME IN ('legACCCreditLimitLevelLine') AND ELEMENTTYPENAME IN ('TABLE')  
Thanks for reading this
Happy Daxing 

Friday, February 22, 2019

Validate WrkCtrId AX 2012/D365

Below are some example to understand Relations between Route, Resource and Resource group tables in AX 2012/D365

if(routeWrkCtrId != "" &&  routeWrkCtrId != _wrkCtrIdToValidate)
    {
        select firstOnly wrkCtrResourceGroupResourceRoute
            where wrkCtrResourceGroupResourceRoute.WrkCtrId == routeWrkCtrId;

        select firstOnly wrkCtrResourceGroupResource
            where wrkCtrResourceGroupResource.WrkCtrId == _wrkCtrIdToValidate;

        if(wrkCtrResourceGroupResource.ResourceGroup != wrkCtrResourceGroupResourceRoute.ResourceGroup)
        {
            throw error(strFmt('@TTT214',WrkCtrResourceGroup::find(wrkCtrResourceGroupResourceRoute.ResourceGroup).WrkCtrId));
        }
    }
    //If resource group is attached to selected opration, validate that selected resource should fall under that resource group.
    else if(prodRoute.activityRequirementSet().resourceGroupRequirement().RecId)
    {
        //retrive operation resource group.
        routeWrkCtrId = prodRoute.activityRequirementSet().resourceGroupRequirement().WrkCtrId;

        select firstOnly wrkCtrResourceGroupResource
                where wrkCtrResourceGroupResource.WrkCtrId == _wrkCtrIdToValidate;

        if(prodRoute.activityRequirementSet().resourceGroupRequirement().RecId != wrkCtrResourceGroupResource.ResourceGroup)
        {
            throw error(strFmt('@TTT214',routeWrkCtrId));
        }
    }
    else
    {
        throw error('@TTT216');
    }

num2Str example AX 2012/Dynamics 365

Below is sample example for the function num2str

static void dtformatNum(Args _args)
{
    real lineNum = 5.69;
    int d = 0;
    ;
    while ((d < 10) && (lineNum != str2num( num2str(lineNum,1,d,1,0) ) ))
        d++;

    info(num2str(lineNum, 1, d, 1, 0));

}

Enum String functions AX 2012

Enum to String conversion using label values.

str dtGetZeroValueReasonCode()
{
    DictEnum        dictEnum;
    int             valueIndex;
    int             enumId;
    str             labelId; 
    str             reasonCode;
    ;

    enumId      = enumNum(rdZeroWeightReasonCode);
    dictEnum    = new DictEnum(enumId);

    if (dictEnum)
    {
        for (valueIndex = 0 ; valueIndex < dictEnum.values(); valueIndex++)
        {         
            labelId = dictEnum.index2LabelId(valueIndex);
            reasonCode += strFmt('%1;',SysLabel::labelId2String(labelId) ? SysLabel::labelId2String(labelId) : dictEnum.index2Label(valueIndex));
        }
    }

    // Remove the trailing ";" if it exist
    if (reasonCode != "")
    {
        reasonCode = strDel(reasonCode,strLen(reasonCode),1);
    } 

    return reasonCode;
}

retrieve enum name from string

zeroWeightReasonCodeStr = zeroWeightReasonCodeElement.innerText();
zeroWeightReasonCode = str2Enum(zeroWeightReasonCode, zeroWeightReasonCodeStr);

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

Error:
Full error is as below, while generating reports in Developer VM.

Unable to connect to the remote server at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext) at Microsoft.WindowsAzure.Storage.Table.CloudTable.Exists(Boolean primaryOnly, TableRequestOptions requestOptions, OperationContext operationContext) at Microsoft.WindowsAzure.Storage.Table.CloudTable.CreateIfNotExists(TableRequestOptions requestOptions, OperationContext operationContext) at Microsoft.DynamicsOnline.Infrastructure.Components.TableAccessor.TableStorageAccessor.PerformOperation(CloudStorageAccount storageAccount, String tableName, Func`1 operation) at

Reason:
Azure emulator service is not running due to port conflict with another windows service.

How to find what is running on what port?

using any of the below commands in cmd will give you list of the ports used by services.

netstat -bano

netstat -a
In my case, those ports were in use by windows application, which i can not stop or change port.

How to solve error?

To resolve this error open CMD with Administrative privileges

Navigate to location: "C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator\"

Execute command AzureStorageEmulator.exe start.

In my case service was not started due to same ports were being used by another application.

I have changed port number for Azure Emulator to run on different port and started service.

Below is Picturization for the same.








Happening

Upgrade from AX 2012 to Latest Dynamics 365 Finance and Operation

Below are the steps defined by sequence. 1. Create new Upgrade project in Dynamics LCS. 2. Create VSTS Project and connect it with L...

Trending now