Thursday, December 31, 2020

Get financial dimension display value using x++

 Code to get dimension display value in ax 2012/D365 FO using x++ 


public str getDimensionDisplayValue(RecId _defaultDimension, Name dimName)
{
  DimensionAttributeValueSetStorage dimStorage;

  dimStorage = DimensionAttributeValueSetStorage::find(_defaultDimension);
  return dimStorage.getDisplayValueByDimensionAttribute(DimensionAttribute::findByName(dimName).RecId);
}
str dimensionValue;
dimensionValue = this.getDimensionDisplayValue(DefaultDimensionRecId, 'Project');

//Where
//defaultDimensionRecId can be PurchTable.Defaultdimension, InventTable.DefaultDimension etc
//'Project' is the name of the financial dimension. It can be 'BusinessUnit' 'CostCenter' etc.


Note: Please refer to the tables below to get display value name.
1. DimensionfinancialTagCtegory
2. OmoperatingUnit (OMOperatingUnitNumber, OMOperatingUnitType)


Tuesday, December 15, 2020

Get active financial dimensions in ax 2012 or D365 using x++

Below is the code to get active financial dimension in ax 2012 or D365 using x++


          DimensionAttributeSetItem  dimAttrSetItem;
          DimensionAttribute  dimAttr;
          DimensionEnumeration dimensionSetId;

          int dimAttrCount;

          dimensionSetId = DimensionCache::getDimensionAttributeSetForLedger();

//Code to get count of active dimensions 

           select count(RecId) from dimAttr
                       where dimAttr.Type != DimensionAttributeType::MainAccount
                 join RecId from dimAttrSetItem
                        where dimAttrSetItem.DimensionAttribute == dimAttr.RecId &&
                                   dimAttrSetItem.DimensionAttributeSet == dimensionSetId;

               info(strFmt("Total active financial dimensions for current legal entity: %1", dimAttr.RecId));

//Code to get active dimensions name

            while select * from dimAttr
                           order by Name
                           where dimAttr.Type != DimensionAttributeType::MainAccount
                     join RecId from dimAttrSetItem
                           where dimAttrSetItem.DimensionAttribute == dimAttr.RecId &&
                                      dimAttrSetItem.DimensionAttributeSet == dimensionSetId        
            {

                    info(dimAttr.Name);

             }


Enjoy :) 

Monday, December 14, 2020

Sync single table in ax 2012 or D365 FO using X++

 Sync a table in ax 2012 or  D365FO using x++.

Create a job in ax 2012 or runnable class in D365FO. Write the following piece of code in it and run the job.


appl.dbSynchronize(tableNum(TableName));


Friday, December 4, 2020

The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:queryBuilderArgs.

 Getting following error while running report in ax 2012.


The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:queryBuilderArgs. The InnerException message was 'Element 'http://tempuri.org/:queryBuilderArgs' contains data from a type that maps to the name 'http://schemas.datacontract.org/2004/07/XppClasses:SRSQueryBuilderArgs'. The deserializer has no knowledge of any type that maps to this name. Consider using a DataContractResolver if you are using DataContractSerializer or add the type corresponding to 'SRSQueryBuilderArgs' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to the serializer.'.  Please see InnerException for more details.


Solution:

1. Stop AOS Service

2. Restart SQl Server Reporting Services

3. Start AOS service

4. Deploy BIServices from Service group in AOT.

5. Refresh report server from caches and reset Date usage (Optional)

Enjoy :) 



Wednesday, November 11, 2020

D365 FO :- Unable to connect to the remote server at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand`1 cmd, IRetryPolicy policy,

 I got following exception while running report in D365 FO.


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 Microsoft.DynamicsOnline.Infrastructure.Components.TableAccessor.TableStorageAccessor.AddRecord[T](........................



After searching, I found that this exception occurs when the Store Emulator is not running. Therefore, you have to start it. Perform the following step to start Store Emulator.

  1. Open Command Prompt as administrator.
  2. Now go to "C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator> AzureStorageEmulator.exe start.




Tuesday, June 2, 2020

Computed Coulmn in Views AX

Here are some examples of Computed column. Create string field in view using computed column and then add any one method from below to that field.

1. Calculate field in View using SysComputedColumn code.

public static server str getOutstanding()
{
    return strFmt("Sum(%1) + Sum(%2)",
            SysComputedColumn::returnField(
            tableStr(TIDIndentOrderUninvoiceTrans),
            identifierStr(TIDIndentOrderPaymentTrans),
            fieldStr(TIDIndentOrderPaymentTrans, amountTendered)),
            SysComputedColumn::returnField(
            tableStr(TIDIndentOrderUninvoiceTrans) ,
            identifierStr(TIDIndentOrderPaymentTrans),
            fieldStr(TIDIndentOrderPaymentTrans, grossAmount)));
}



2. Convert null Date to Max Date in view using SysComputedColumn code.

public static server str ReleasePostingDate()
{
 
    return SysComputedColumn::if(
            SysComputedColumn::isNullExpression(SysComputedColumn::returnField(
            tableStr(TIDAPUninvoiceConsignmentItem) ,
            identifierStr(LedgerJournalTableRealease),
            fieldStr(LedgerJournalTable, PostedDateTime))),
            SysComputedColumn::cast(strFmt("'%1'",DateTimeUtil::date(DateTimeUtil::maxValue())),'NVARCHAR'),
            SysComputedColumn::cast(SysComputedColumn::returnField(
            tableStr(TIDAPUninvoiceConsignmentItem) ,
            identifierStr(LedgerJournalTableRealease),
            fieldStr(LedgerJournalTable, PostedDateTime)),'NVARCHAR')
            );
}

3.

Saturday, March 28, 2020

The option 4 for querystore query_capture_mode is not supported



It is caused due to a setup mismatch between AzureSQL and SQL server. To solve this issue you have to run this SQL statement
ALTER DATABASE [QueryStoreDB] SET QUERY_STORE (QUERY_CAPTURE_MODE = ALL); in the Azure SQL (UAT) environment before you export the database.
Other solution is: 
The solution is to rename the bacpac file to zip, extract the content and locate the "model.xml" file. Copy the "model.xml" file to a new location where you can locate it easily. Rename the zip file back to bacpac. Edit the "model.xml" file:
From:
<Property Name="QueryStoreCaptureMode" Value="4" />
To:
<Property Name="QueryStoreCaptureMode" Value="2" />
Save the "model.xml" file.
Now you need to use the "/ModelFilePath" parameter of SqlPackage.exe, and point it to your updated "model.xml" file. This will instruct the SqlPackage.exe to read the updated "model.xml" file and ignore the one from within the bacpac file.
After adding /ModelFilePath parameter of SqlPackage.exe, the command will look like this: 
C:\>"Program Files (x86)\Microsoft SQL Server\140\DAC\bin\SqlPackage.exe" /Action:Import /SourceFile:"bacpacfile" /mfp:"modelfilepath" /tsn:servername /tdn:dbname /p:CommandTimeout=1200

Wednesday, March 25, 2020

Copy Data of Custom fields from PurchLine to PurchaseOrderVersions


  1. Add fields by using table extensions to the PurchLine and PurchLineHistory tables.
  2. Create a new table map containing the fields that must be copied. 
  3. Implement the new table map on the two new table extensions.
  4. Create a new class to implement the PurchLineIVersioningFieldSet interface and implement the following required methods.
    • copyVersion method - Copies data between two records of the new table map type.
    • fieldSetTableMapId method - Returns the ID of the new table map.
    • isChangeConfirmationRequired method - Returns true or false based on whether the change to the newly added field values requires a confirmation to be created.
  5. Now run build + sync.

Customization Analysis Report (CAR) OR Check BP error using cmd in ax d365

Open command prompt as administrator and write below command to check BP error or car.



K:\AosService\PackagesLocalDirectory\bin\xppbp.exe -metadata=K:\AosService\PackagesLocalDirectory -all -model="ApplicationSuite" -xmlLog=C:\temp\BPCheckLogcd.xml -module="ApplicationSuite" -car=c:\temp\BPReport.xlsx

where ApplicationSuite = "YourModelName"

It will create an xml file named (BPCheckLodcd.xml) and excel file named (BPReport.xlsx) at location C:\temp. You can change this path according to you. This report is called Customization Analysis Report (CAR).

Monday, March 23, 2020

Run db sync using cmd in ax d365

Here is the command to run db sync using cmd in ax d365. Open command prompt as administrator and write the below code.

K:\> AosService\PackagesLocalDirectory\Bin\Microsoft.Dynamics.AX.Deployment.Setup.exe  -bindir "K:AosService\PackagesLocalDirectory"  -metadatadir K:AosService\PackagesLocalDirectory -sqluser username  -sqlserver  serverName  -sqldatabase databasename -setupmode sync -syncmode fullall -isazuresql false -sqlpwd pswd