RSS

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

 
Leave a comment

Posted by on August 23, 2020 in D365, Uncategorized

 

Tags:

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());
}
}

}

 
Leave a comment

Posted by on July 13, 2020 in HRM, Uncategorized

 

Get Schedule Batch job date and time


/// <summary>
/// Gets the scheduled date and time of job.
/// </summary>
/// <returns>
/// Scheduled date and time of job.
/// </returns>
public UtcDatetime scheduledDateTime()
{
BatchJob batchJob;

select firstonly OrigStartDateTime from batchJob
where batchJob.RecId == BatchHeader::getCurrentBatchTask().BatchJobId ;

return batchJob.OrigStartDateTime;
}

 
Leave a comment

Posted by on July 13, 2020 in Batch jobs

 

Tags:

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.

 

 
Leave a comment

Posted by on July 6, 2020 in LCS, Uncategorized

 

Tags:

Electronic reporting by example: Create a new Bank file definition


Thomas Widmer's D365 Blog

Electronic Reporting seems to be an integral part of the future of Dynamics 365 that can be used for importing and exporting data of all kinds above and beyond the capabilities of the static data entities, so it is worth finding out how this works.
In the following we will do this by example.

Online ressources

As a starting point there is standard microsoft documentation and this great blog with detaillied instructions:

High level overview for creation of new Bank file

  1. Extend a preexisting bank format
  2. Define new export format – Constants
  3. Define new export format – Data fields
  4. Add transformations for correct formatting
  5. Add new calculated fields
  6. Calculate total fields
  7. Add user input parameters
  8. Add validations for readable errors
  9. Activate

BACS: 1. Extend a preexisting bank format

It is always easier to start based on preexisting work instead of starting from scratch, so to create a new…

View original post 277 more words

 
Leave a comment

Posted by on February 17, 2020 in Uncategorized

 

Filter product dimensions

Filter product dimensions

Dynamics Ax

Sometimes it’s necessary to filter an inventDim record and only get the active product dimensions. This can be useful if you, for example, define additional data for an item and its product dimensions and have to call this data in a sales order line where the associated inventDim record also contains storage dimensions like site and warehouse.

In this case you want to strip out the unwanted dimensions from the inventDim record which you can do by using following code:

2020-02-01 15_07_36-InventDim _ InventDim filtern _ Produktdimensionen - OneNote

Basically you define a new inventDim buffer, transfer the data from your current inventDim record and find the active dimensions for the specific item. After that is done you can clear all dimensions which are not active and search for the correct inventDim record.

View original post

 
Leave a comment

Posted by on February 17, 2020 in Uncategorized

 

Query-join

Query-join

Dynamics Ax

This is a small code snippet which shows off an example of a join within a query.

inkedqueryjoin_li1

You can join as many tables as you would like. In this example i joined the table “EcoResColor” and “EcoResProductMasterColor”.

View original post

 
Leave a comment

Posted by on February 17, 2020 in Uncategorized

 

Call a filtered form with x++

Call a filtered form with x++

Really nice want to reblog it on my blog

Dynamics Ax

If you want to call a form which is prefiltered you have multiple options to do so.

You can of couse use a menu item but you can also achieve this with code.

In this example we want to show all contacts which are connected to the selected customer on the address form. The idea is to create a button and call the contact form prefiltered with the current customer.

First of all you need a button on your form which is your entry point to the logic behind it. Ideally this is an unbound button-control without fancy details other than a label.

ButtonForm

The actual logic is placed in an eventhandler. Best bet is to subscribe to the clicked-event.

ButtonLogic.png

As you can see the logic itself is quite simple. We get the current dirPartyTable record with the dirPartyLocation, pass it to args and call the menu item of the contacts…

View original post 17 more words

 
Leave a comment

Posted by on February 17, 2020 in Uncategorized

 
Quote

If you ever wondered how to manipulate a query which manages the data of a form, there is an easy way of doing this using CoC. In this example a customer wanted the contacts, that are shown in the lookup for the customers, limited to contacts who are not already assigned to an address in […]

via CoC form query — Dynamics Ax

CoC form query — Dynamics Ax

 
Leave a comment

Posted by on February 17, 2020 in Dynamics 365 for Operations

 

What Is PowerApps


PowerApps is the collections of apps, services, connectors and different data platform which provides rapid application development environment to build a custom apps.

Using this PowerApps we can build custom business apps as per our business requirements.
These PowerApps custom application support the different online and on-premise data sources like (Excel, Office 365Share Point, dynamics 365, SQL Server etc).
Using this PowerApps application we can transform our manual business processes to digital , automated processes.

These PowerApps can run easily on browser and mobile devices.
It’s a new feature to build a business apps without coding.
It’s also provides a platform to developers to interact with data and metadata.

using PowerApps we can create three types of apps:
1. canvas :  Start with blank apps.
2. model-driven : Start with data model first.
3. portal : Used to create external website.

Common Data Service : is the data platform that comes with PowerApps and allows you to store and model business data.
It’s the platform on which Dynamics 365 applications are built;
if you’re a Dynamics customer, your data is already in the Common Data Service.

For more information visit Microsoft site.
https://docs.microsoft.com/en-us/powerapps/maker/index

 
Leave a comment

Posted by on February 17, 2020 in PowerApps, Uncategorized

 
 
iotsolution.se

This is your site about D365 (Finance and Supply Chain Management), IoT (Internet of Things) and HoloLens

Omni 365

Dynamics 365 Finance and Operations Blog

DIY D365

Power Platform Done Your Way

Azure Integration for Dynamics 365

Azure Integration for Dynamics 365 Unified Operations, Logic Apps, Azure Functions, REST

Birger Larsen - AX / Dynamics 365 blog on WMS

WMS, Distribution, Logistics, Birger, Larsen, AX, 2012, WAX, TRAX, Dynamics 365

Rizwan Ahmed

Microsoft Dynamics 365, Commerce, Solution architect, helping clients achieve operational excellence.

iamJoshKnox

Dynamics 365, Business Applications, and Me!

Dynamics Journal

A blog on Dynamics 365 for Operations - Retail

Middleware In The Cloud

Blog focused on Microsoft Middleware running in the cloud. Content provided by Kent Weare

Ryan Maclean

My low-code approach to CRM development

Debajit's Power Apps & Dynamics 365 Blog

All about Power Apps & Dynamics

Rajpal's view on D365FO

Enhance your D365FO skills, leave your valueable feedback and suggestions

vmoskalenko blog

D365FO, AX, Windows, Azure

Brett McKenzie

.NET, Azure, and Office dev

Ajit Patra

Microsoft Technologies and Dynamics 365 Blogs