Sunday, April 27, 2025

How to Call Key Vault Secrets in an Azure Function



    1. To access Key Vault secrets from an Azure Function, you need to install the following NuGet packages in your project:

  • Azure.Identity
  • Azure.Security.KeyVault.Secrets

    2. Below is the method I wrote to access Key Vault secrets.

internal string GetSecret(string secretName)
{
    string keyVaultName = Environment.GetEnvironmentVariable("keyVaultName");

    string kvUri = $"https://{keyVaultName}.vault.azure.net";

    SecretClient client = new SecretClient(new Uri(kvUri), new DefaultAzureCredential());
    var secret = client.GetSecretAsync(secretName).Result;

    return secret.Value.Value;
}

    3. The Key Vault name is retrieved from an environment variable.

string keyVaultName = Environment.GetEnvironmentVariable("keyVaultName");

    4. I trigger the GetSecret method from the Azure Function and assign the secret value to the response.

    5. After publishing the Azure Function, you need to add the Key Vault name as an environment variable in the function app settings.


Follow these steps to configure the identity and assign the roles:

    1. Open the Identity section in the Azure Function app settings, enable the status, and click on Azure role assignments.



    2. Click on Add role assignment, and set the scope to Key Vault.

    3. Assign the appropriate resource (Key Vault) and role(Key Vault Secrets User).


    4. The role is now assigned, and the Azure Function can access the Key Vault.




    OutPut: 

 
Keep Daxing!!

Tuesday, April 15, 2025

Convert JSON to CSV/Text file in Logic app

Convert JSON to CSV/Text file in Logic app

This is the full step-by-step process, and I have provided its output below.


I used the below JSON to test this.

[
  {
    "Id": "1234",
    "Name": "Test1",
    "Phone": "700000"
  },
   {
    "Id": "4567",
    "Name": "Test2",
    "Phone": "800000"
  },
   {
    "Id": "6789",
    "Name": "Test3",
    "Phone": "900000"
  }
]

Please follow the below steps.


        Step 1: I have used 'When a HTTP request is received'  action.

        



Way 1: Manual step(Will add fields manually and assign the values) I have pipe CSV.

        Step 2: Under data operations, I chose 'Create CSV table.'  
                      

  •  We need to assign a value to the 'Value' node using the following expression, based on the header fields .
  •  I am generating the file with a pipe('|') that's why I have selected the custom.                   

  Value : item()?['Name']


        Step 3:  used the 'Compose' action and applied the 'Replace with pipe' function.

        replace(body('Create_CSV_table'), '|,|', '|')


        Step 4: The resulting file is stored in a blob        


    OutPut:   





Way 2: Automatic

    If we want same Column names then use Automatic system will generate the file with commas (',') separated.

    



Keep Daxing!!


Wednesday, April 9, 2025

Move the database from Dev to UAT or Tier1 to Tier2

Move the database from Dev to UAT or Tier1 to Tier2.

  • Mostly, databases are moved from Tier 2 to Tier 1 environments.
  • But in our case, most of the functional setup and configurations were completed in the Dev (Tier 1) environment, and the team needs this data to be moved to Sandbox (Tier 2). 
  • Since transactional data is involved, we cannot use Data Entities.
Therefore, we followed the process below:

Step-by-Step Process to Move the Database from Dev (Tier 1) to UAT/Sandbox (Tier 2)

1. Export the AXDB from Dev (Tier 1) (.bak)
        Export the AXDB database into a .bak file using one of the following methods:

        Way1: Right-click on the AXDB database and Select Tasks > Back Up.

        Way2: Use the following SQL script to back up the database:

      BACKUP DATABASE [AXDB] TO DISK = N'D:\Backup\AxDB_Dev.bak' WITH NOFORMAT, INIT, 
        NAME = 'AxDB_Dev Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10


2. Restore the Backup to a New Database

    Use the Restore Database option in SSMS to restore the .bak file to a new database (AXDB_Dev).


3. Run Required SQL Scripts

    Execute below SQL scripts in the newly restored database.

update sysglobalconfiguration
set value = 'SQLAZURE'
where name = 'BACKENDDB'
 
update sysglobalconfiguration
set value = 1
where name = 'TEMPTABLEINAXDB'
 
drop procedure XU_DisableEnableNonClusteredIndexes
drop schema [NT AUTHORITY\NETWORK SERVICE]
drop user [NT AUTHORITY\NETWORK SERVICE]
drop user axdbadmin
drop user axdeployuser
drop user axmrruntimeuser
drop user axretaildatasyncuser
drop user axretailruntimeuser

4. Export the Database to a .bacpac File

    This is required to move the database to Tier 2 via LCS.

    Way1:

  • Right-click the restored database, Go to Tasks > Export Data-tier Application.

  •  Select a local folder and export the database as a .bacpac file

  • click on Next and Finish

        Export duration depends on database size

 

    Way2 (Command Line): Use SqlPackage.exe to export the database to .bacpac.

  • Ensure SqlPackage.exe is installed on your machine.
  • Path will change for SqlPackage.exe, before executing the command please check the correct path

        Run the following command (in CMD):

Cd C:\Program Files\Microsoft SQL Server\160\DAC\bin\SqlPackage.exe /a:export /ssn:localhost 
    /sdn:<database name to export> /tf:<File path> /p:CommandTimeout=1200 
    /p:VerifyFullTextDocumentTypesSupported=false /SourceTrustServerCertificate:True

    I have used below command.

Cd C:\Program Files\Microsoft SQL Server\160\DAC\bin


"C:\Program Files\Microsoft SQL Server\160\DAC\bin\SqlPackage.exe" /a:export /ssn:localhost 
    /sdn:<database name to export> /tf:"D:\Test\AxDB_dev.bacpac" /p:CommandTimeout=1200 
    /p:VerifyFullTextDocumentTypesSupported=false /SourceTrustServerCertificate:True


5. Upload the .bacpac File to LCS

  • Go to LCS > Asset Library > Database Backup
  • Upload the .bacpac file
  • Set the Backup Type as: Product Database (SQL Server or .bak)


6. Import Database into Tier 2 Environment

    Go to the Tier 2 environment in LCS

  • Click Maintain > Move database

  • Select Import database
  • Choose the uploaded .bacpac file from the asset library

  • Complete the import wizard and confirm

The import process may take some time depending on database size.


7. Enable All Users

After the import is complete, connect to the new database using SSMS and run the following query.

update userinfo set enable = 1



Keep Daxing!!

Wednesday, April 2, 2025

How to add Admin role to user from SQL in D365FO

 How to add Admin role to user from SQL in D365FO

In SecurityRole table we will find all roles.

Execute the below statement to know the system admin role Recid.

Select Recid,* from SecurityRole where NAME like 'sys%'


Insert the data into SECURITYUSERROLE  table with username and role recid. Execute the below statement.

insert into SECURITYUSERROLE (USER_, SECURITYROLE,ASSIGNMENTSTATUS,ASSIGNMENTMODE)
values('Kishore', 235,1,1)

If you want to update you can use the below statement.

update SECURITYUSERROLE
set SECURITYROLE = 235 where  USER_ = 'Kishore'

Reference : Click here


Keep Daxing!!