Showing posts with label Ax. Show all posts
Showing posts with label Ax. Show all posts

Sunday, July 24, 2022

Report name in report contract cannot be null or empty.

 I ran into this issue while running the invoice journal report.



After spending sometime, I'm able to find the solution. To fix this issue just run  the following code in the runnable class:

class RunnableClass
{
    /// <summary>
    /// Run the class with the specified arguments.
    /// </summary>
    /// <param name = "_args">The specified arguments.</param>
    public static void main(Args _args)
    {
        PrintMgmtReportFormat                     printMgmtReportFormat;
        
        ttsbegin;
        select forupdate printMgmtReportFormat
            where printMgmtReportFormat.Name == 'ReportName.Report';
        printMgmtReportFormat.System = NoYes::Yes;
        printMgmtReportFormat.doUpdate();
        ttscommit;
    }
}

Create Offset Ledger Dimension using String Value in D365FO

Create offset ledger dimension using string value in D365FO X++:

Str offsetAccountValue = XXXX-XXXXXX-XXXX.XXXX-XXXX-XXXX-XXXXXX-XXXXXX


public RefRecId createOffsetLedgerDimension(str _offsetAccountVal)
    {
        LedgerAccountContract                      ledgerAccountContract, ledgerAccountContractLoc;
        List                                                      valueContracts, valueContractsLoc;
        DimensionHierarchy                           dimHierarchy;
        int                                                        dimCounterLoc;
        DimensionAttribute                            dimAttributeLoc;
        str                                                        dimAttValueLoc;
        DimensionAttributeValue                   dimAttributeVal, dimAttributeValLoc;
        DimensionAttributeValueContract     dimAttributeValueContract, dimAttributeValueContractLoc;
        MainAccountNum                              mainAccountId, mainAccountIdLoc;
        DimensionStorage                              dimStorage, dimStorageLoc;
        
        valueContracts                      = new List(Types::Class);
        valueContractsLoc                = new List(Types::Class);
        ledgerAccountContract         = new LedgerAccountContract();
        ledgerAccountContractLoc   = new LedgerAccountContract();

        select firstonly * from dimHierarchy
                                    where dimHierarchy.StructureType == DimensionHierarchyType::DataEntityLedgerDimensionFormat
                                    && dimHierarchy.IsDraft          == NoYes::No;
        
        if(offsetAccountVal)
        {
            for(int counterLoc = 0; counterLoc <= strLen(offsetAccountVal); counterLoc++)
            {
                dimCounterLoc++;
                dimAttributeLoc = DimensionAttribute::find(DimensionHierarchyLevel::findByDimensionHierarchyAndLevel(dimHierarchy.RecId, dimCounterLoc).DimensionAttribute);
                                    
                if(strFind(offsetAccountVal, "-", counterLoc, strLen(offsetAccountVal)) > 0)
                {
                    dimAttValueLoc = subStr(offsetAccountVal, counterLoc, (strFind(offsetAccountVal, "-", counterLoc, strLen(offsetAccountVal)) - counterLoc));
                                        
                    if(strFind(dimAttValueLoc, "-",0, strLen(dimAttValueLoc)) > 0)
                    {
                        dimAttValueLoc = subStr(dimAttValueLoc, 0, (strFind(dimAttValueLoc, "-",0, strLen(dimAttValueLoc)) - 1));
                    }
                    counterLoc = strFind(offsetAccountVal, "-", counterLoc, strLen(offsetAccountVal));
                }
                else
                {
                    dimAttValueLoc = subStr(offsetAccountVal, counterLoc, strLen(offsetAccountVal));
                    counterLoc     = strLen(offsetAccountVal);
                }
                dimAttributeValLoc = DimensionAttributeValue::findByDimensionAttributeAndValue(dimAttributeLoc, dimAttValueLoc);
                if(dimAttributeLoc.Name == "MainAccount")
                {
                    if(!MainAccount::findByMainAccountId(dimAttValueLoc).RecId)
                    {
                        throw Error(strFmt("Invalid value of %1",dimAttributeLoc.Name));
                    }
                    mainAccountIdLoc = dimAttValueLoc;
                    continue;
                }
                if(dimAttributeValLoc.RecId)
                {
                    dimAttributeValueContractLoc = new DimensionAttributeValueContract();
                    dimAttributeValueContractLoc.parmName(dimAttributeLoc.Name);
                    dimAttributeValueContractLoc.parmValue(dimAttributeValLoc.CachedDisplayValue);
                    valueContractsLoc.addEnd(dimAttributeValueContractLoc);
                }
                else
                {
                    throw Error(strFmt("Invalid value of %1",dimAttributeLoc.Name));
                }
            }
            ledgerAccountContractLoc.parmMainAccount(mainAccountIdLoc);
            ledgerAccountContractLoc.parmValues(valueContractsLoc);
            dimStorageLoc = DimensionServiceProvider::buildDimensionStorageForLedgerAccount(ledgerAccountContractLoc);
            return DimensionAttributeValueCombination::find(dimStorageLoc.save()).RecId;
        }
        return 0;
        
    }

You can get format combination from the below line. Currently it's for ledger dimension, you can also get the same for other dimension by changing the type of enum (DimensionHierarchyType).

select firstonly * from dimHierarchy
                                    where dimHierarchy.StructureType == DimensionHierarchyType::DataEntityLedgerDimensionFormat
                                    && dimHierarchy.IsDraft          == NoYes::No;


Thursday, December 2, 2021

No print management settings are applicable so no document is produced

 Getting error message while printing report that  "No print management settings are applicable so no document is produced."



Solution:

Go to that module --> Setup > Forms > Form setup > General tab > Print management 

Right click and create new for all the reports you want to print.




Done.

Wednesday, June 30, 2021

Error importing database: Could not read schema model header information from package. The model version '3.6' is not supported

Error:

Error importing database: Could not read schema model header information from package. The model version '3.6' is not supported.




In order to fix this issue, you need to download and install the latest Data Tier Application Framework(18.2).

(Here is the link: https://www.microsoft.com/en-us/download/confirmation.aspx?id=58207)


After installed the latest Framework, open command prompt as administrator and write the below command:

C:\Program Files\Microsoft SQL Server\150\DAC\bin>SqlPackage.exe /Action:import /Sourcefile:"C:\temp\UATDataBasebackup.bacpac" /tsn:localhost /tdn:AxDB_New /p:CommandTimeout="0"


It worked.


Friday, May 21, 2021

Get Reference of Original Sales Order from Credit Note Sales Order using X++

If you create new sales order and create credit note of any previous sales order, then here is the way to find reference of previous sales order (invoice number) through newly created credit note sales order using x++.

InventTransOrigin::findByInventTransId(SalesLine::Find(this.SalesId).InventTransIdReturn).ReferenceId;


Note:
If you create a credit note simply by using the "Credit Note" button on the sales order form, Ax copies the previous invoice lines into the original sales order with a negative sign. In this case you do not need any additional reference to the original sales order as you are still using the same sales order.

Sunday, February 21, 2021

Import backpac file to Sql Server

Here are the steps below to imort the .bacpac file to the sql server.
Every time you import the .bacpac file, it will always create a new database on the sql server.

Step-1: Run command prompt as administrator and write the following command in it.

"C:\Program Files (x86)\Microsoft SQL Server\140\DAC\bin\SqlPackage.exe" /Action:Import /SourceFile:"J:\AXDB_UAT.bacpac" /tsn:dev630a58c756-1  /tdn:SSProd /p:CommandTimeout="0"

Here:
tsn is target server name
tdn is target database name
New database created successfully here.

Step-2: Now rename previous database and set newly created database named as "AxDB" after stopped following services.

World wide web publishing service
Management Reporter 2012 process service
Microsoft Dynamics 365 Unified Operations: Batch Management Service
Microsoft Dynamics 365 Unified Operations: Data Import Export Framework Service                                                                                                      
                                                                                       OR

you can rename the database by using following commands:

Set database to single user 
ALTER DATABASE dbName
SET SINGLE_USER WITH ROLLBACK IMMEDIATE 

Rename database
ALTER DATABASE dbName MODIFY NAME = dbNewName

Set database back to multiuser
ALTER DATABASE dbName
SET MULTI_USER WITH ROLLBACK IMMEDIATE

Step-3: Start the following services  

World wide web publishing service
Management Reporter 2012 process service
Microsoft Dynamics 365 Unified Operations: Batch Management Service
Microsoft Dynamics 365 Unified Operations: Data Import Export Framework Service    

Step-4: Now run db sync using the below command

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

Done!



Friday, January 22, 2021

The required assembly 'Microsoft.Dynamics.Framework.Tools.ApplicationExplorer.dll' does not exists.

I was applying the latest Platform update to one of our internal server when I got this error.

Error:

"The required assembly 'Microsoft.Dynamics.Framework.Tools.ApplicationExplorer.dll' does not exists."




Solution:

To solve this error, just copied the dll file to the location where it popped up and that's it. Now, run the step again and the issue is resolved. 
(Hint: you can search this dll file in that drive where VS is installed).


Friday, January 8, 2021

Enable maintenance mode on local VM in D365FO

I found the following warning message while creating/activating new financial dimension on Local VM in d365 FO. For resolving this issue put environment on maintenance mode.


OR




In order to put environment in maintenance mode follow these steps:

1. Run Command prompt as administrator.

2. Execute this command

C:\AosService\PackagesLocalDirectory\Bin\Microsoft.Dynamics.AX.Deployment.Setup.exe --metadatadir C:\AosService\PackagesLocalDirectory --bindir C:\AosService\PackagesLocalDirectory\Bin --sqlserver . --sqldatabase axdb --sqluser AOSUser --sqlpwd AOSWebSite@123 --setupmode maintenancemode --isinmaintenancemode true 


3. Restart AOS service from IIS

4. Now, Create/Activate financial dimension or  do the changes that you want. once you done. Revert back to environment in normal mode by using this command.

C:\AosService\PackagesLocalDirectory\Bin\Microsoft.Dynamics.AX.Deployment.Setup.exe --metadatadir C:\AosService\PackagesLocalDirectory --bindir C:\AosService\PackagesLocalDirectory\Bin --sqlserver . --sqldatabase axdb --sqluser AOSUser --sqlpwd AOSWebSite@123 --setupmode maintenancemode --isinmaintenancemode false



Done :) 

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.