Thursday, February 14, 2019

Get Tax Amount for each line in Ax 2012/Dynamics 365 for finance and operation

Way 1->
private TaxAmountCur getTaxAmount(TableId   _transTableId, RefRecId _transRecId)
    {
        TaxTrans    taxTrans;
        select sum(SourceTaxAmountCur) from taxTrans
                where taxTrans.SourceTableId == _transTableId
                    && taxTrans.SourceRecId == _transRecId;
        return taxTrans.SourceTaxAmountCur > 0 ? taxTrans.SourceTaxAmountCur : -taxTrans.SourceTaxAmountCur;
    }

Way - 2->
    public TaxAmountCur getSalesTaxAmount(TableId   _transTableId, RefRecId _transRecId)
    {
        TaxAmountCur    taxAmountCur;
        TransDate       transDate = DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone());
        SalesLine       SalesLine = SalesLine::findRecId(_transRecId);

        TaxAmountCur = Tax::calcTaxAmount(salesline.TaxGroup,
                                            salesline.TaxItemGroup,
                                            transDate,
                                            salesline.CurrencyCode,
                                            salesline.LineAmount,
                                            TaxModuleType::Sales,
                                            salesline.SalesQty,
                                            salesline.SalesUnit,
                                            salesline.ItemId,
                                            TaxDirection::OutgoingTax);

        return taxAmountCur;
    }

Way 3->
TmpTaxWorkTrans             tmpTax;
            SalesTable                  salesTable;
            SalesTotals                 salesTotals;
            SalesLine                   SalesLine = SalesLine::findRecId(_transRecId);
 
            salesTable  = SalesTable::find(salesline.SalesId);
            salesTotals = SalesTotals::construct(salesTable);
            salesTotals.calc();
            tmpTax.setTmpData(salesTotals.tax().tmpTaxWorkTrans());
            select sum(TaxAmount) from tmpTax
                where tmpTax.InventTransId == salesline.InventTransId;            
            taxAmountCur = tmpTax.TaxAmount;


Way 4-> (If price incl of tax)
(salesline.calcLineAmount() - salesline.calcLineAmountExclTax())

Wednesday, January 30, 2019

Class DimensionLookupHelper for generating Dimension Data on Lookup in Dynamics 365 FO

DimensionValueLookupHelper::lookupDimensionValues(DimensionAttribute::findByLocalizedName('<DimensionName>', false, SystemParameters::find().SystemLanguageId), <FormStringControl>);

Tuesday, January 29, 2019

Backup and restore in another ENV Dynamics 365 Finance and operations


1.       Take the AxDB database backup
2.       Do the Full Build.
3.       Do the Database Synchronize 
4.       Connect the LCS and download the Database 
5.       Create the new Database with Name : UATBackUp81.
6.       Restore the downloaded Database from LCS to UATBackUp81.
7.       Need to change the UATBackUp81
a.        Security User details
Script:
CREATE USER axdeployuser FROM LOGIN axdeployuser
EXEC sp_addrolemember 'db_owner', 'axdeployuser'

CREATE USER axdeployextuser WITH PASSWORD = '<password from LCS>'
IF EXISTS (select * from sys.database_principals where type = 'R' and name = 'DeployExtensibilityRole')
BEGIN
    EXEC sp_addrolemember 'DeployExtensibilityRole', 'axdeployextuser'
END

CREATE USER axdbadmin WITH PASSWORD = '<password from LCS>'
EXEC sp_addrolemember 'db_owner', 'axdbadmin'

CREATE USER axruntimeuser WITH PASSWORD = '<password from LCS>'
EXEC sp_addrolemember 'db_datareader', 'axruntimeuser'
EXEC sp_addrolemember 'db_datawriter', 'axruntimeuser'

CREATE USER axmrruntimeuser WITH PASSWORD = '<password from LCS>'
EXEC sp_addrolemember 'ReportingIntegrationUser', 'axmrruntimeuser'
EXEC sp_addrolemember 'db_datareader', 'axmrruntimeuser'
EXEC sp_addrolemember 'db_datawriter', 'axmrruntimeuser'

CREATE USER axretailruntimeuser WITH PASSWORD = '<password from LCS>'
EXEC sp_addrolemember 'UsersRole', 'axretailruntimeuser'
EXEC sp_addrolemember 'ReportUsersRole', 'axretailruntimeuser'

CREATE USER axretaildatasyncuser WITH PASSWORD = '<password from LCS>'
EXEC sp_addrolemember 'DataSyncUsersRole', 'axretaildatasyncuser'

ALTER DATABASE SCOPED CONFIGURATION  SET MAXDOP=2
ALTER DATABASE SCOPED CONFIGURATION  SET LEGACY_CARDINALITY_ESTIMATION=ON
ALTER DATABASE SCOPED CONFIGURATION  SET PARAMETER_SNIFFING= ON
ALTER DATABASE SCOPED CONFIGURATION  SET QUERY_OPTIMIZER_HOTFIXES=OFF

ALTER DATABASE <imported database name> SET COMPATIBILITY_LEVEL = 130;
ALTER DATABASE <imported database name> SET QUERY_STORE = ON;

update [dbo].[SYSSERVICECONFIGURATIONSETTING]
set value ='<tenant ID from existing database>'
where name = 'TENANTID'

update dbo.POWERBICONFIG
set TENANTID = '<tenant ID from existing database>'

update dbo.PROVISIONINGMESSAGETABLE
set TENANTID = '<tenant ID from existing database>'
GO
-- Begin Refresh Retail FullText Catalogs
DECLARE @RFTXNAME NVARCHAR(MAX);
DECLARE @RFTXSQL NVARCHAR(MAX);
DECLARE retail_ftx CURSOR FOR
SELECT OBJECT_SCHEMA_NAME(object_id) + '.' + OBJECT_NAME(object_id) fullname FROM SYS.FULLTEXT_INDEXES
    WHERE FULLTEXT_CATALOG_ID = (SELECT TOP 1 FULLTEXT_CATALOG_ID FROM SYS.FULLTEXT_CATALOGS WHERE NAME = 'COMMERCEFULLTEXTCATALOG');
OPEN retail_ftx;
FETCH NEXT FROM retail_ftx INTO @RFTXNAME;

BEGIN TRY
    WHILE @@FETCH_STATUS = 0 
    BEGIN 
        PRINT 'Refreshing Full Text Index ' + @RFTXNAME;
        EXEC SP_FULLTEXT_TABLE @RFTXNAME, 'activate';
        SET @RFTXSQL = 'ALTER FULLTEXT INDEX ON ' + @RFTXNAME + ' START FULL POPULATION';
        EXEC SP_EXECUTESQL @RFTXSQL;
        FETCH NEXT FROM retail_ftx INTO @RFTXNAME;
    END
END TRY
BEGIN CATCH

PRINT error_message()
END CATCH

CLOSE retail_ftx; 
DEALLOCATE retail_ftx;
-- End Refresh Retail FullText Catalogs
8.       Changes the names like AxDB to AxDB_standard ,  UATBackUp81 to AXDB
USE master;
GO 
ALTER DATABASE AxDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
ALTER DATABASE AxDB MODIFY NAME = AxDB_Standard ;
GO 
ALTER DATABASE AxDB_ Standard SET MULTI_USER
GO
---------------------------------------------------------------------------

USE master;
GO 
ALTER DATABASE UATBackUp81 SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
ALTER DATABASE UATBackUp81 MODIFY NAME = AxDB ;
GO 
ALTER DATABASE AxDB SET MULTI_USER
GO
9.       Do the Full DB Synchronize

Thursday, January 24, 2019

Self-service deployment in Dynamics 365 for finance and operartions

https://docs.microsoft.com/en-us/dynamics365/unified-operations/dev-itpro/database/copy-database-from-azure-sql-to-sql-server

Export:
Export .bacpac file from LCS

Import Database:
cd C:\Program Files (x86)\Microsoft SQL Server\140\DAC\bin

SqlPackage.exe /a:import /sf:D:\Exportedbacpac\my.bacpac /tsn:localhost /tdn:<target database name> /p:CommandTimeout=1200

Note:
During import, the user name and password aren't required. By default, SQL Server uses Microsoft Windows authentication for the user who is currently signed in.

Note:
tsn (target server name) – The name of the SQL Server to import into.
tdn (target database name) – The name of the database to import into. The database should not already exist.
sf (source file) – The path and name of the file to import from.

Update Database:
Query:
CREATE USER axdeployuser FROM LOGIN axdeployuser
EXEC sp_addrolemember 'db_owner', 'axdeployuser'

CREATE USER axdbadmin FROM LOGIN axdbadmin
EXEC sp_addrolemember 'db_owner', 'axdbadmin'

CREATE USER axmrruntimeuser FROM LOGIN axmrruntimeuser
EXEC sp_addrolemember 'db_datareader', 'axmrruntimeuser'
EXEC sp_addrolemember 'db_datawriter', 'axmrruntimeuser'

CREATE USER axretaildatasyncuser FROM LOGIN axretaildatasyncuser
EXEC sp_addrolemember 'DataSyncUsersRole', 'axretaildatasyncuser'

CREATE USER axretailruntimeuser FROM LOGIN axretailruntimeuser
EXEC sp_addrolemember 'UsersRole', 'axretailruntimeuser'
EXEC sp_addrolemember 'ReportUsersRole', 'axretailruntimeuser'

CREATE USER axdeployextuser FROM LOGIN axdeployextuser
EXEC sp_addrolemember 'DeployExtensibilityRole', 'axdeployextuser'

CREATE USER [NT AUTHORITY\NETWORK SERVICE] FROM LOGIN [NT AUTHORITY\NETWORK SERVICE]
EXEC sp_addrolemember 'db_owner', 'NT AUTHORITY\NETWORK SERVICE'

UPDATE T1
SET T1.storageproviderid = 0
    , T1.accessinformation = ''
    , T1.modifiedby = 'Admin'
    , T1.modifieddatetime = getdate()
FROM docuvalue T1
WHERE T1.storageproviderid = 1 --Azure storage

ALTER DATABASE [<your AX database name>] SET CHANGE_TRACKING = ON (CHANGE_RETENTION = 6 DAYS, AUTO_CLEANUP = ON)
GO
DROP PROCEDURE IF EXISTS SP_ConfigureTablesForChangeTracking
DROP PROCEDURE IF EXISTS SP_ConfigureTablesForChangeTracking_V2
GO
-- Begin Refresh Retail FullText Catalogs
DECLARE @RFTXNAME NVARCHAR(MAX);
DECLARE @RFTXSQL NVARCHAR(MAX);
DECLARE retail_ftx CURSOR FOR
SELECT OBJECT_SCHEMA_NAME(object_id) + '.' + OBJECT_NAME(object_id) fullname FROM SYS.FULLTEXT_INDEXES
WHERE FULLTEXT_CATALOG_ID = (SELECT TOP 1 FULLTEXT_CATALOG_ID FROM SYS.FULLTEXT_CATALOGS WHERE NAME = 'COMMERCEFULLTEXTCATALOG');
OPEN retail_ftx;
FETCH NEXT FROM retail_ftx INTO @RFTXNAME;

BEGIN TRY
WHILE @@FETCH_STATUS = 0 
BEGIN 
PRINT 'Refreshing Full Text Index ' + @RFTXNAME;
EXEC SP_FULLTEXT_TABLE @RFTXNAME, 'activate';
SET @RFTXSQL = 'ALTER FULLTEXT INDEX ON ' + @RFTXNAME + ' START FULL POPULATION';
EXEC SP_EXECUTESQL @RFTXSQL;
FETCH NEXT FROM retail_ftx INTO @RFTXNAME;
END
END TRY
BEGIN CATCH
PRINT error_message()
END CATCH

CLOSE retail_ftx; 
DEALLOCATE retail_ftx;
-- End Refresh Retail FullText Catalogs


Start to use the new database:
To switch the environment and use the new database, first stop the following services:
1. World Wide Web Publishing Service
2. Microsoft Dynamics 365 Unified Operations: Batch Management Service
3. Management Reporter 2012 Process Service

After the services have been stopped, rename the AxDB database AxDB_orig, rename your newly imported database AxDB, and then restart the three services.

To rename the database, use the following ALTER DATABASE command:

Thursday, January 3, 2019

Get objects MetaData details in Dynamics 365 for finance and operation

StringEnumerator   objectNameString;
str objectName;
objectNameString = Microsoft.Dynamics.Ax.Xpp.MetadataSupport::ClassNames();
     while (objectNameString.moveNext())
     {
            objectName =  objectNameString.Current;
            AxClass classSt = Microsoft.Dynamics.Ax.Xpp.MetadataSupport::GetClass(objectName);

           //  classSt .
     }

Thursday, December 27, 2018

Data Deduplication Overview

Data Deduplication:

Data deduplication involves finding and removing duplication within data without compromising its fidelity or integrity. The goal is to store more data in less space by segmenting files into small variable-sized chunks (32–128 KB), identifying duplicate chunks, and maintaining a single copy of each chunk. Redundant copies of the chunk are replaced by a reference to the single copy. The chunks are compressed and then organized into special container files in the System Volume Information folder.
The result is an on-disk transformation of each file as shown in Figure 1. After deduplication, files are no longer stored as independent streams of data, and they are replaced with stubs that point to data blocks that are stored within a common chunk store. Because these files share blocks, those blocks are only stored once, which reduces the disk space needed to store all files. During file access, the correct blocks are transparently assembled to serve the data without calling the application or the user having any knowledge of the on-disk transformation to the file. This enables administrators to apply deduplication to files without having to worry about any change in behavior to the applications or impact to users who are accessing those files.

Friday, December 21, 2018

Restart environment services


Restart environment services

To restart a specific service in a deployed environment,
1.    In LCS, open the appropriate project, and select the environment to restart the service for.
2.    On the Environment details page, select Maintain > Restart services.
3.    In the Restart a service dialog box, select the service to restart, and then select OK.
4.    To view the updated status, refresh the page.

Merge from release to other branch


Merge from release to other branch


 
1.   Navigate to source control explore, click à Project and click à node release
2.   Select release version, which u want to merge in different branch
3.   Right click à Release version à Branching and merging à Merge
4.   Verify source release version branch and also Target branch, which you want to merge
5.   Select à version Type à Latest version
6.   Click à Finish
7.   Example: Source control VSTS Service links is https://<Org-Name>.visualstudio.com/<ProjectName>/<ProjectNameTeam>


Code upgrade with Release:

Code upgrade with Release:


1.    In your LCS project, select the Code upgrade tile.
2.    Click Ã  Add, and then enter a name and description. Select the version you are upgrading from dropdown and then click Create.
a.    If you are upgrading your code from Dynamics AX 2012 R3, select the version you are upgrading from. You will be prompted to upload a zipped version of your Dynamics AX 2012 R3 model store file.
b.    If the Estimation Only check box is selected, the tool only generates a report and does not check in or create a new code branch in Azure DevOps for you. You should use this option if you want to evaluate the potential size of the work involved in upgrading before you commit to the actual upgrade.
  1. Click Ã  Analyze code in the bottom right corner. The code upgrade process will start. This typically takes 40 minutes for a large solution to complete. When complete, return to the Code upgrade tile in LCS to view the results.
  2. The code upgrade service creates a new branch and checks in the upgraded code to your Azure DevOps project. After the upgrade process is complete, your code will exist in a new branch under the Releases folder. The branch name is suffixed with the date and time of the upgrade.

Skip Inventory reservation on Sales order lines in D365FO

[ExtensionOf(classStr(InventUpd_Reservation))] final class InventUpd_ReservationCls_SAN_Extension {     void updateNow()     {         if(mo...