web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Active Discussion

TableSynchSetup.Mode::Force and Upgrade Codeunits when reducing the size of text or code fields

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

TableSynchSetup.Mode::Force and Upgrade Codeunits when reducing the size of text or code fields

 

When designing Upgrade Codeunits, it is possible to specify in the upgrade function a brutal Force action performed at runtime as per documentation

 https://docs.microsoft.com/en-us/dynamics-nav/upgrade-codeunits#upgradedunctions

Force

The Microsoft Dynamics NAV Server will force the changes on the table and delete any data in fields that are affected by the change. This option is intended to be used for the tables and fields that you want to discontinue. If you want to save the data from this table, you should use the Copy or Move mode.

 

With the advent of SaaS deployments and in Dynamics 365 Business Central Spring 2019 release (version 14.x), the execution of this parameter has been made more restrictive and until September 2020 Cumulative Update (CU) it would have thrown an error if the synchronization command would have run not under -ForceSync conditions.

NOTE: this restriction applies when changing the size of a column.


To showcase and reproduce the behavior, you could follow these repro steps:

 

  • Run CSIDE Development environment 
  • Change Customer (table 18) "Address 2" field length from 50 to 20 (within a Cronus there is more than one record with this field populated with a string longer than 20 chars)
  • IMPORTANT: Compile with option to synchronize Later 
  • Import and compile the following simple codeunit. NOTE: the codeunit will apply an upgrade with synch force (highlighted in red)

 

OBJECT Codeunit 50333 UpgradeWithForce

{

  OBJECT-PROPERTIES

  {

    Date=;

    Time=;

    Modified=Yes;

    Version List=;

  }

  PROPERTIES

  {

    Subtype=Upgrade;

    OnRun=BEGIN

            UpgradeCustomer(TableSyncSetup);

          END;

 

  }

  CODE

  {

    VAR

      TableSyncSetup@1000 : Record 2000000135;

 

    [TableSyncSetup]

    PROCEDURE UpgradeCustomer@2(VAR TableSynchSetup@1002 : Record 2000000135);

    VAR

      DataUpgradeMgt@1001 : Codeunit 9900;

    BEGIN

      DataUpgradeMgt.SetTableSyncSetup(DATABASE::Customer,0,TableSynchSetup.Mode::Force);

    END;

 

    BEGIN

    END.

  }

}

 

  • Run an elevated PowerShell ISE and do Sync-navtenant BC140 -Mode Sync. You will get the following error, due to the security enforcement mentioned in this blog.

 

Sync-navtenant : The following SQL error was unexpected:

String or binary data would be truncated.

The statement has been terminated.

At line:1 char:1

+ Sync-navtenant nav -Mode Sync

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (0:Int32) [Sync-NAVTenant], NavCommandException

    + FullyQualifiedErrorId : MicrosoftDynamicsNavServer$nav,Microsoft.Dynamics.Nav.Management.Cmdlets.SyncNavTenant

 

NOTE: If you try to use web or windows client now (or whatever client), you will see that the system is not accessible and you cannot connect.

NOTE: running Sync-navtenant BC140 -Mode ForceSync will perform the action.

 

The problem of ForceSync is related to an unwanted raise of permissions in synchronizing the environment that might introduce a problem if some other disruptive breaking change has been applied not on purpose.

To be sure that these unwanted changes does not break through, since September 2020 CU 14.17, it is made possible to specify the following server side parameter in customsettings.config file:

<add key="ForceSyncFromUpgradeCodeunit" value="true" />

After restarting the service, if a synchronization is performed with -Mode Sync and an upgrade codeunit has specified a Force option parameter, this will not throw any error.

All other unwanted breaking changes that does not pass through an upgrade codeunit with Force option parameter set will raise an error.

Below links to KB article and relevant TFS entry

https://support.microsoft.com/en-us/help/4576662/cumulative-update-16-for-microsoft-dynamics-365-business-central-april

364588

A SQL error displays in Sync-NAVTenant -Mode Sync when you synchronize with a TableSyncSetup Upgrade codeunit that runs with TableSynchSetup.Mode::Force.

 

Please note that Dynamics NAV 2017 and backward versions, the synchronization with -Mode Force would have worked without the needs of specifying anything server side.

Dynamics NAV 2018 implemented the server side parameter already, since September 2019, with CU 21 https://support.microsoft.com/en-us/help/4518533/cumulative-update-21-for-microsoft-dynamics-nav-2018-build-35815

310480

An upgrade codeunit is specifying the Table Synch. Setup Mode that the force mode is not forcing the table synchronization as expected.

  • Marco Mels Profile Picture
    Microsoft Employee on at

    Thank you for sharing Duilio!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 796 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 481 Super User 2026 Season 2

#3
AndrewThomas81 Profile Picture

AndrewThomas81 377 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans