Re-sequencing of fields in Data Management in D365 F&SCM

Recently we got a required to rearranging/resequencing of fields when we export the data from Data Management framework for in Excel or CSV format.

Below are the steps we can do that :

  • Create a export data project

  • Add the entity for which data need to to exported

  • Once entity is add in the selected entities list there is a option Entity Attribute

  • What entity attribute form do? It provide the list of Fields and there sequence.

  • As shown below you can arrange the order in which data required for Integration layer or based 3rd Party Integration data mapping .
  • Now when ever we export or 3rd Party make a call to this data project it will export the data in define format.

Read File’s from SFTP Server and Write data in AX365 (PART 1)

In Part 1, will create a project with basic SFTP functionality which we will use in AX in Part 2

Basic Step is to add the Parameters to set the SFTP details.

Tips:

If we are using Port 22 then no need to use a prefix of SFTP in your Host because 21 is for FTP and 22 is for SFTP

Your File path should start from the directory root folder not from the SFTP server name.

To connect to the SFTP Server. I used SSH.NET Dll.

Create a New C# Library project, Right Click on your project, click on Manage NuGet Packages and Install ssh.net In your project. It will add a reference of DLL into your project.

Add a reference of this dll in your class

using Renci.SshNet;

Now we need to write a method to make a connection,

1
2
3
4
5
6
7
8
9
10
11
12
13
public SftpClient OpenSFTPConnection(string host, int port, string username, string password)
{
    if (this.sftpClient == null)
    {
        this.sftpClient = new Renci.SshNet.SftpClient(host, port,      username, password);
    }
   if (!this.sftpClient.IsConnected)
    {
        this.sftpClient.Connect();
    }
    return this.sftpClient;
}

This method will return all the files present in the directory

1
2
3
4
public List<string> GetDirectories(SftpClient _SftpClient, string path)
{
        return _SftpClient.ListDirectory(path)/*.Where(n => n.IsDirectory).ToList();
}

This method will return the stream which we can use to read the content of the files.

public Stream DownloadFile(SftpClient _SftpClient, string sourcePath)
 {
        var memoryStream = new MemoryStream();
        _SftpClient.DownloadFile(sourcePath, memoryStream);
        memoryStream.Position = 0;
        return memoryStream;
}

I also got a requirement to move files to a different folder after writing data in AX. Below method will do that magic.

1
2
3
4
public void MoveFile(SftpClient _SftpClient, string sourcePath, string destinationPath, bool isPosix)
{
        _SftpClient.RenameFile(sourcePath, destinationPath, isPosix);
}

Final Code for our library project will look like this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using Renci.SshNet;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MySshNet
{
    public class sftpConnection
    {
        public SftpClient sftpClient;
        public SftpClient OpenSFTPConnection(string host, int port, string username, string password)
        {
            if (this.sftpClient == null)
            {
                this.sftpClient = new Renci.SshNet.SftpClient(host, port, username, password);
            }
            if (!this.sftpClient.IsConnected)
            {
                this.sftpClient.Connect();
            }
            return this.sftpClient;
        }
        public List<string> GetDirectories(SftpClient _SftpClient, string path)
        {
            return _SftpClient.ListDirectory(path)/*.Where(n => n.IsDirectory)*/.Select(n => n.Name).ToList();
        }
        public void MoveFile(SftpClient _SftpClient, string sourcePath, string destinationPath, bool isPosix)
        {
            _SftpClient.RenameFile(sourcePath, destinationPath, isPosix);
        }
        public Stream DownloadFile(SftpClient _SftpClient, string sourcePath)
        {
            var memoryStream = new MemoryStream();
            _SftpClient.DownloadFile(sourcePath, memoryStream);
            memoryStream.Position = 0;
            return memoryStream;
        }
    }
}

Now Just build your project then go to your projects bin\Debug folder and copy both Dll’s. paste the DLL’s to your AX extension Bin Folder so we can use it in our AX project.

Tips:

We need to add our Dll’s in our extension Bin folder so It can go through with check in to the next environments.

Reference: https://dynamicsax4u.wordpress.com/2020/08/18/read-files-from-sftp-server-and-write-data-in-ax365-part-1/?blogsub=confirming&blogsub=confirming#subscribe-blog

HcmPositionHirarchy To whom position needs to report in upper ranking in D365 FinOps

static void AlfPositionHirarchyUP(Args _args)
{
HcmWorker                   HcmWorker;
HcmPositionWorkerAssignment HcmPositionWorkerAssignment;
HcmPositionHierarchy        HcmPositionHierarchy;
HcmPositionRecId            positionRecId;

positionRecId = HcmPosition::findByPosition(HcmWorker::      findByPersonnelNumber(‘701027’).primaryPositionId()).RecId;

while(positionRecId>0)
{
select * from HcmPositionHierarchy
where HcmPositionHierarchy.Position ==positionRecId;

positionRecId=HcmPositionHierarchy.ParentPosition ;
if(HcmPositionHierarchy.ParentPosition)
{
info(HcmWorker::find(HcmPosition::getReportsToWorker(HcmPositionHierarchy.Position)).name());
}
}

}

Create Azure Connector for Lifecycle Services

 how to set up the Azure connection required for Dynamics 365 For Finance and Operations Deploy through Lifecycle Services. First of all, we open our project from Lifecycle Services. Under Environments, we click on Microsoft Azure settings.

Your Azure Connectors will appear on the Azure connectors tab, if available. It appears on the list because I have a connection for this environment. After completing these steps, when we look, here again, the connection must be established. We can start adding a new link by clicking the + Add button.


 

In the window that opens, Name will be the name we provide for the link. Azure subscription ID we want to establish a connection to the section Azure, you must enter the code for the membership. Tenant Domain information will come automatically. You should mark Azure Resource Manager (ARM) as
Yes. We go to the next page with Next.


 

You should have given the Dynamics Deployment Services authorization I mentioned in my previous article before this step. If you have, you will see the screen below. We go to the next page with Next.


 

Before continuing, we need to download the Management certificate and install it on the Microsoft Azure Portal. You can leave this page open.


 

We login to the Azure portal and select the membership you want to connect with.


 

We click on the Management Certificates section and click the Upload button in the window that opens.


 

We select and upload the certificate we downloaded.


 

When you see this screen, the installation process is completed.


 

We can return to the screen we stayed in Lifecycle Services and continue with the Next button. After this stage, we can continue without errors.

 

We usually choose West Europe in the Azure region.

 

After clicking the Connect button, you should see an item in your Azure Connection list as follows. At this stage, the connection has been completed.


 

In this article, I tried to explain how to set up an Azure connection via Lifecycle ServicesSince Dynamics 365 is a structure that runs on Azure, it is necessary to have information about many Azure subjects.