Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

Import from csv files brings wrong data values

(0) ShareShare
ReportReport
Posted on by 157

Hello to everyone.

I have an issue after reading a file from csv. 
The csv has 22 rows, but some of them are empty in some lines and in the container that brings back the data, some values are in wrong position.

for example: 

line 1 : value 1; value2; ; value4; value5

it brings back  :                              [1value1, [2value2, [3value4, [4value5

when it has to bring back              [1value1, [2value2, [3null , [4value4, [5value5

Is it possible to fix this issue somehow?


The code i use to read the file is 

 #File
        container               currentLine;
        int                     totalOfLines;
        CommaTextStreamIo       localStream;
        Num                     number;
            
       
        FileUpload fileUploadControl = this.getFormControl(dialog, FileUploadName);
        
        FileUploadTemporaryStorageResult fileUploadResult = fileUploadControl.getFileUploadResult();
        
        if (fileUploadResult != null && fileUploadResult.getUploadStatus())
        {
            textFile = fileUploadResult.getDownloadUrl();
        }
        
        localStream = CommaTextStreamIo::constructForRead(File::UseFileFromURL(textFile));
        
        
        localStream.inFieldDelimiter("\;");
        localStream.inRecordDelimiter("\n");
    
        currentLine = localStream.read();
        totalOfLines  ;
        
        
        while(currentLine)
        {
            
            number = conPeek(currentLine,1);

            info(strFmt("Number : %1",number));

            currentLine = localStream.read();

        }

  • Suggested answer
    SGbron Profile Picture
    157 on at
    RE: Import from csv files brings wrong data values

    Finally I found the reason for missing colums.

    I had set the delimeter to ' ; ' but for some reason it doesn't read correct the file when null values exist. the correct delimeter is ' , '.

  • nmaenpaa Profile Picture
    101,156 Moderator on at
    RE: Import from csv files brings wrong data values

    Could you change your code a bit, to print the contents of currentLine (using con2str(currentLine))?

    And share with us some real CSV rows, and real output from your code? Thanks!

  • SGbron Profile Picture
    157 on at
    RE: Import from csv files brings wrong data values

    Hello Nikolaos.

    By brings back I mean that in lines:

    while(currentLine)

           {

               number = conPeek(currentLine,1);

               info(strFmt("Number : %1",number));

               currentLine = localStream.read();

           }

    where it reads the file, in the container takes the values that i am writing

    It misses the null value.

  • nmaenpaa Profile Picture
    101,156 Moderator on at
    RE: Import from csv files brings wrong data values

    Hi SGbron,

    what do you mean by "brings back"? What part of your code handles this "bringing back"? Doesn't your code simply print one entry in the infolog for each row in your CSV file?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,280 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,038 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans