web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Want to import csv file using code. Getting exception error.

(0) ShareShare
ReportReport
Posted on by 518

Hello all,

www.tech.alirazazaidi.com/.../

with reference to above post I have written the code but I am getting error that is in screenshot attached.

I am using runbase batch for the file selection and getting the file also.

The code I have written is

public void importCsvFile(Args _args)
{
    #File
    CommaTextIo             csvFile;
    Name FirstName;
    Name LastName;
    StudentInfo  studentInfo;
    //FilenameOpen        filenameOpen; //= “c:\\StudentInfo.csv”;//To assign file name
    Container           record;
    boolean first = true;
    ;
  
    csvFile = new CommaTextIo(filenameOpen, #IO_Read);  // csvFile is getting null value here in this par and the filenameOpen is having the file name.
    if (! csvFile || csvFile.status() != IO_Status::Ok)
    {
        throw error("@SYS19358");      
    }
    while (csvFile.status() == IO_Status::Ok)
    {
        record = csvFile.read();// To read file
        if (record)
        {
            if (first)  //To skip header
            {
                first = false;
            }
            else
            {
                FirstName = conpeek(record, 1);//To peek record
                LastName  = conpeek(record, 2);
                _StudentInfo.FirstName =FirstName;
                _StudentInfo.LastName  =LastName;
                _StudentInfo.insert();
            }
        }
    }
}

error-csv.png

How can I read the csv file or what is the mistake in this part of code.

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Sukrut Parab Profile Picture
    71,710 Moderator on at

    As per error suggest you have to assert file IO permissions .  Refer below link

    community.dynamics.com/.../codeaccesspermission-problem

  • Siddhant Singh Profile Picture
    518 on at

    Hi Sukrut,

    fileIoPermission = new FileIoPermission(filenameOpen, 'r');

    I have added the above line of code but still the error is the same.

  • Suggested answer
    Heinz Schweda Profile Picture
    1,367 on at

    Hi, since this is a RunBaseBatch class, the code may be executed on the server side. Is the specified file name also accessible from the AOS server?

    Regards Heinz

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans