Import CSV file into Dynamics 365 for Operation using X++

Hi Everyone,

In my today post i am going to show you, how we can read a CSV file in D365 for operation using temporary blob storage technique.

As i have said, the file which i am going to read will be stored temporarily in azure blob storage and then AX will read the file directly from the temporary blob storage.

the below mentioned line provides a dialog to upload the file into blob storage.

FileUploadTemporaryStorageResult result = File::GetFileFromUser() as FileUploadTemporaryStorageResult;

Code:

List data = new List(Types::String);
container dataContainer;

FileUploadTemporaryStorageResult result = File::GetFileFromUser() as FileUploadTemporaryStorageResult;

if (result && result.getUploadStatus())
{
using (var sr = new System.IO.StreamReader(result.openResult(), System.Text.Encoding::get_UTF8()))
{

var text = sr.ReadLine();

While(!System.String::IsNullOrEmpty(text))
{

data = strSplit(text, ‘,’);  //Split the lines based on ‘,’ it’s return type is List.
dataContainer = conNull();
dataContainer = data.pack(); // moves the List value to container. the first three values are system value. actual data will be read from container position 4.
date = str2Date(conPeek(dataContainer, 4), 213);
StoreNum = conPeek(dataContainer, 5);

info(strfmt(“store number : %1, Transaction date : %2”, StoreNum , date );
//To read next line
text = sr.ReadLine();
}

}

}

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s