D365fo Archives - Monsieur Winner https://blog.monsieurwinner.com/category/d365fo/ MS D365FO || Monsieur D365FO Fri, 04 Aug 2023 10:46:08 +0000 en-US hourly 1 https://wordpress.org/?v=6.6.2 https://i0.wp.com/blog.monsieurwinner.com/wp-content/uploads/2022/09/cropped-Winner-.png?fit=32%2C32&ssl=1 D365fo Archives - Monsieur Winner https://blog.monsieurwinner.com/category/d365fo/ 32 32 209261758 Generate SQL Server self-signed certificate https://blog.monsieurwinner.com/2022/07/29/generate-sql-server-self-signed-certificate/ https://blog.monsieurwinner.com/2022/07/29/generate-sql-server-self-signed-certificate/#respond Fri, 29 Jul 2022 22:02:24 +0000 https://blog.monsieurwinner.com/?p=361 Part of the requirement to deploy D365FO on-premises, is the SQL server certificate. Recently, I worked on rotating the SQL

The post Generate SQL Server self-signed certificate appeared first on Monsieur Winner.

]]>
Part of the requirement to deploy D365FO on-premises, is the SQL server certificate.

Recently, I worked on rotating the SQL server certificate for an environment.

I used the following as stated on Microsoft docs, I used :


# If Remoting, execute
#.\Configure-SQLCert-AllVMs.ps1 -ConfigurationFilePath .\ConfigTemplate.xml

.\Configure-SQLCert.ps1 -PfxCertificatePath “.\Certs\SQL1.contoso.com.pfx”

But then I got some errors (because I was not using the latest Infrastructure folder).

Another way of generating the SQL server certificate.


# Manually create certificate for each SQL Node (i.e. 2 nodes = 2 certificates)
# Run script on each node
$computerName = $env:COMPUTERNAME.ToLower()
$domain = $env:USERDNSDOMAIN.ToLower()
$listenerName = 'monsieurwinner'
$cert = New-SelfSignedCertificate -Subject "$computerName.$domain" -DnsName "$listenerName.$domain", $listenerName, $computerName -Provider 'Microsoft Enhanced RSA and AES Cryptographic Provider' -CertStoreLocation "cert:\LocalMachine\My" -KeyAlgorithm "RSA" -HashAlgorithm "sha256" -KeyLength 2048

The post Generate SQL Server self-signed certificate appeared first on Monsieur Winner.

]]>
https://blog.monsieurwinner.com/2022/07/29/generate-sql-server-self-signed-certificate/feed/ 0 361
Copy production database to DEV environment in D365FO https://blog.monsieurwinner.com/2022/07/12/copy-production-database-to-dev-environment-in-d365fo/ https://blog.monsieurwinner.com/2022/07/12/copy-production-database-to-dev-environment-in-d365fo/#respond Tue, 12 Jul 2022 06:55:02 +0000 https://blog.monsieurwinner.com/?p=306 Database movements are activities that do occur during the lifecycle of Finance and Operation project. There are different database movement

The post Copy production database to DEV environment in D365FO appeared first on Monsieur Winner.

]]>
Database movements are activities that do occur during the lifecycle of Finance and Operation project.

There are different database movement scenarios as the need arises. Please check Microsoft article

In the post, I will take you through a step-by-step on how to Copy production database to DEV environment in D365FO.

LCS(Life cycle service) is the entry point of every D365FO project and we can perform almost all actions on our environments on LCS like, Refresh, Export, and Import database. However, Microsoft does not allow us to move a Production database directly to the DEV environment.  We can achieve that with the steps below:

 

Step 1. Take a backup of the Live database to test. (Database refresh)

This can be done on LCS portal by doing a database refresh.

Step 2. Export the refreshed data base to Asset library on LCS

Step3. Download the database from LCS to the Development environment.

To download, click on the database file on LCS and voila.

Note that the database is saved on the asset library as a .bacpac file. We are import this file using powershell and Sqlpackage

Step4. Get the Sqlpackage

Download here

It is advisable to have both the database file and the sqlpackage file in the same directory. Before importing, rename your current AxDB to AxDbold with the following SQL script in Management studio.

 

USE master
GO
ALTER DATABASE AxDB
SET SINGLE_USER
WITH ROLLBACK IMMEDIATE
GO
ALTER DATABASE AxDB
Modify Name = AxDBold
GO
ALTER DATABASE AxDBold
SET MULTI_USER
GO
While setting the database back to Multi user you might get an error. Use:
SET DEADLOCK_PRIORITY HIGH
ALTER DATABASE AXDB SET MULTI_USER WITH ROLLBACK IMMEDIATE

Then create a new database called AxDB.

Step5. Import the .bacpac database.

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

Here is an explanation of the parameters:

  • tsn (target server name) – The name of the Microsoft SQL Server instance 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.

Below my result :

.\SqlPackage.exe /a:import /sf:C:\testbackup.bacpac /tsn:localhost /tdn:axdb /p:CommandTimeout=1200

 

Step6. Update the databse

Run the following script against your database to add the users you deleted while creating .bacpac file.

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 WITH PASSWORD = '<password from LCS>'
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
-- 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.

 

The post Copy production database to DEV environment in D365FO appeared first on Monsieur Winner.

]]>
https://blog.monsieurwinner.com/2022/07/12/copy-production-database-to-dev-environment-in-d365fo/feed/ 0 306
Form Data Field Onmodified event handler in D365FO https://blog.monsieurwinner.com/2022/07/06/onmodified-event-handler-d365fo/ https://blog.monsieurwinner.com/2022/07/06/onmodified-event-handler-d365fo/#respond Wed, 06 Jul 2022 09:35:20 +0000 https://blog.monsieurwinner.com/?p=288 Bonjour les Amis. A short snippet to show how to use the OnModified field event handler in D365FO. Event handlers

The post Form Data Field Onmodified event handler in D365FO appeared first on Monsieur Winner.

]]>
Bonjour les Amis.

A short snippet to show how to use the OnModified field event handler in D365FO.

Event handlers are available on different part on a Form in D365FO: On the Form datasource, form control, form object itself.

In this post we are working on a Form datasource.

I added a custom field “JournalId” on the LedgerJournalTransTable. The aim here, is to link Item movement journal transaction(s) with the General journal, So when I select the journal Id on the form, I will be able to perform some actions.

Firstly I locate my field on the LedgerJournalTrans Form Datasource.

 

 

/// <summary>
/// Return Total cost amount from Inventory movement journal lines.
/// </summary>
/// <param name=”sender”></param>
/// <param name=”e”></param>
[FormDataFieldEventHandler(formDataFieldStr(LedgerJournalTransDaily, LedgerJournalTrans, JournalId), FormDataFieldEventType::Modified)]
public static void JournalId_OnModified(FormDataObject sender, FormDataFieldEventArgs e)
{
FormDataSource LedgerJournalTrans_ds = sender.datasource();
LedgerJournalTrans ledgerJournalTrans = ledgerJournalTrans_ds.cursor();

InventJournalTrans inventJournalTrans;

select Sum(CostAmount) from inventJournalTrans where inventJournalTrans.JournalId == ledgerJournalTrans.JournalId;

ledgerJournalTrans.AmountCurDebit = inventJournalTrans.CostAmount;
}

Merci.

 

The post Form Data Field Onmodified event handler in D365FO appeared first on Monsieur Winner.

]]>
https://blog.monsieurwinner.com/2022/07/06/onmodified-event-handler-d365fo/feed/ 0 288