Wednesday, October 18, 2023

Shrink log D365FO log file

 Shrink log D365FO log file 

Select DB -> Right click -> Tasks -> Shrink -> Files

select file type as "Log".

Note down the value of file name.




Right click the Database -> New query -> Execute below query.

       ALTER DATABASE AXDB

        SET RECOVERY SIMPLE

        GO

      -- DBCC SHRINKFILE (filename , 1)

        DBCC SHRINKFILE ('AXDB-17Mar_log', 1)

        GO

        ALTER DATABASE AXDB

        SET RECOVERY FULL


** replace your file name

Tuesday, September 26, 2023

Restore/move D365 database

 Restore data base from same tenant (company)


1. Open as Administrator PowerShell
Install if not installed d365fo tools in power shell
- Install-Module -Name d365fo.tools
- Invoke-D365InstallSqlPackage

2. Restore database
if BACPAC file
in powershell
- Import-D365Bacpac -ImportModeTier1 -BacpacFile "C:\temp\CLI TEST1backup.bacpac" -NewDatabaseName "AxDB_20211104" -ShowOriginalProgress

if BAK file go to Microsoft SQL Server Management Studio
Databases node / Right click / Restore Database...
General / Source / Device / click ... button
Click add button select BAK file and click OK and then again OK
Destination / Database change to AxDB_20211104 (date)
Files page (at right)
make sure that Restore As columnt has different files from Original File Name, change from AXDB_FromProdRep1 to AXDB_20211104_FromProdRep1, both lines
Click OK to start process

3. Stop environment
powershell
- Stop-D365Environment
Open IIS manager / Application Pools / AOSService / stop
Close all visual studio. Re open visual studio. Check tray for IISExpress. Right click in tray and Exit

4. Switch databases
In powershell
- Switch-D365ActiveDatabase -SourceDatabaseName "AxDB_20211104" -DestinationSuffix "_old"
Where _old is postfix for currently used AxDB, it will be called AxDB_old

5. Start environment
In powershell
- Start-D365Environment
Open IIS manager / Application Pools / AOSService / start
Close all visual studio. Re open visual studio.
Dynamics 365 / Synchronize database...

For tier2 environments like UAT it is possible to do it from LCS:
Open full environment details
Maintain / Move database
Export database - fill create BACPAC file and upload it to LCS
Import database - will import database from BACPAC file from LCS

To take backups in Microsoft SQL Server Management Studio
Righr click on data base Tasks / Back Up...
Back up type : Full
Destination / Back up to: Disk
Files - change the file name of back up for example AxDB_20211103.bak
Backup Options: Compression can be enabled - Set backup compression: Compress backup. LCS has limit of 14 Gb to upload. Therefore might be usefull.
Also shrink DB might be used: https://daxonline.org/1734-axdb-shrink.html

D365FO documentation:
https://github.com/d365collaborative/d365fo.tools/tree/development/docs

BAK/BACKBAK difference:
https://www.sqlservercentral.com/forums/topic/diff-between-bak-and-backpac-files

Monday, August 28, 2023

Synchornize the D365FO database using command prompt

 K:\AosService\PackagesLocalDirectory\Bin\SyncEngine.exe -syncmode=fullall -metadatabinaries=K:\AosService\PackagesLocalDirectory -connect="Data Source=localhost;Initial Catalog=AxDB;Integrated Security=True;Enlist=True;Application Name=SyncEngine" -fallbacktonative=False -verbosity=Diagnostic

Monday, April 3, 2023

From date and To date range in Dynamic Query

  private Query buidDynamicsQuery(Query _query)

    {

        this.retrieveQueryFilters(_query);

        QueryBuildDataSource qbdsPriceDiscAdmTrans = _query.dataSourceTable(tableNum(PriceDiscAdmTrans));

        qbdsPriceDiscAdmTrans.addRange(fieldNum(PriceDiscAdmTrans, AccountCode)).value(queryValue(PriceDiscProductCodeType::All));

        qbdsPriceDiscAdmTrans.addRange(fieldNum(PriceDiscAdmTrans, relation)).value(queryValue(PriceType::PriceSales));


        if (currencyCode)

        {

            qbdsPriceDiscAdmTrans.addRange(fieldNum(PriceDiscAdmTrans, Currency)).value(queryValue(currencyCode));

        }


        if (toDate)

        {

            qbdsPriceDiscAdmTrans.addRange(fieldNum(PriceDiscAdmTrans, FromDate)).value(queryRange(null, toDate));

        }


        if (fromDate)

        {

            qbdsPriceDiscAdmTrans.addRange(fieldNum(PriceDiscAdmTrans, ToDate)).value(queryRange(fromDate, null));

            qbdsPriceDiscAdmTrans.addRange(fieldNum(PriceDiscAdmTrans, ToDate)).value(queryValue(dateNull()));

        }


        return _query;

    }


How to override form data source field lookup method.

 /// <summary>

/// Handles events raised by <c>SalesTable</c> form.
/// </summary>
public class SalesTableEventHandler
{
    /// <summary>
    /// Post event handler for <c>SalesTable</c> <c>SalesLine</c> Initialized event.
    /// </summary>
    /// <param name=“_sender”></param>
    /// <param name=“_e”></param>
    [FormDataSourceEventHandler(formDataSourceStr(SalesTable, SalesLine), FormDataSourceEventType::Initialized)]
    public static void SalesLine_OnInitialized(FormDataSource _sender, FormDataSourceEventArgs _e)
    {
        var overrides = SalesTableFormExtensionOverrides::construct();
 
        _sender.object(fieldNum(SalesLine, ItemId)).registerOverrideMethod(methodStr(FormDataObject, lookup),
            methodStr(SalesTableFormExtensionOverrides, ItemId_OnLookup), overrides);
    }
}
 
/// <summary>
/// Contains methods which are used to override <c>SalesLine</c> data source field methods.
/// </summary>
public class SalesTableFormExtensionOverrides
{
    protected void new()
    {
    }
 
    /// <summary>
    /// Constructs a new instance of <c>SalesTableFormExtensionOverrides</c> class.
    /// </summary>
    /// <returns>
    /// A <c>SalesTableFormExtensionOverrides</c> class.
    /// </returns>
    public static SalesTableFormExtensionOverrides construct()
    {
        return new SalesTableFormExtensionOverrides();
    }
 
    /// <summary>
    /// Provides a lookup for the <c>InventTable</c> table
    /// </summary>
    /// <param name = "_callingControl">
    /// The form string control object with which to perform the lookup.
    /// </param>
    public void ItemId_OnLookup(FormStringControl _callingControl)
    {
        SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(InventTable), _callingControl);
 
        sysTableLookup.addLookupfield(fieldNum(InventTable, ItemId));
        sysTableLookup.addLookupfield(fieldNum(InventTable, NameAlias));
 
        sysTableLookup.performFormLookup();
    }
}