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)

Import file on network in Batch job

(0) ShareShare
ReportReport
Posted on by 810

Hi all,

Can anyone please help me out from this issue. i m not able to read csv file data while scheduling that batch job.

i have schedule batch job through class, in that run method i have create code for reading csv file from path and inserting data into table.

below is the code for creating the RunbaseBatch job.

#File
IO iO;
CustAccount custAccount;
Name        custname;
FilenameOpen filename = @"C:\test\File1.csv";//To assign file name
Container record;
boolean first = true;
Table1 table1;
;
iO = new CommaTextIo(filename,'R');
if (! iO || iO.status() != IO_Status::Ok)
{
  throw error("@SYS19358");
}
while (iO.status() == IO_Status::Ok)
{
  record = iO.read();// To read file
  if (record)
  {
    if (first) //To skip header
    {
      first = false;
    }
    else
    {
      table1.Name = conpeek(record, 1);//To peek record
      table1.CustAccount = conpeek(record, 2);
      table1.insert();
      info(strfmt('%1--%2',custAccount,custname));
    }
  }
}

I m not able to read data from csv file from this line

iO = new CommaTextIo(filename,'R');

If i have run only for getting the list of csv file then it's giving me the all csv file from the folder.

*This post is locked for comments

I have the same question (0)
  • Crispin John Augustine Profile Picture
    37,081 on at

    Can you try creating a TextIO instance instead, also the declaration?

  • Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at

    Are you sure that the file exist on the server where the AOS is running and that the AOS service access has permissions to read it? If you test it on client, it will run on a (potentially) different computer and under a different account, so it's not a very useful test.

    I would also expect it to throw an error about missing FileIOPermission. And don't forget to build CIL.

  • UmesH@ Profile Picture
    810 on at

    Hi martin,

    Yes, file is on server and i have test it. and also test through Job, getting all well.

    but while scheduling RunBaseBatch csv file data not reading. even i have give full access to the folder and all files.

    after CIL i m scheduling BatchJob.

  • UmesH@ Profile Picture
    810 on at

    Hi Crispin John Augustine,

    I have used all class Object like TextIO, CommaIO, CommaTextIO, AsciiIO, TextBuffer, StreamReader, IO etc...

  • Crispin John Augustine Profile Picture
    37,081 on at

    An Extension to Martin's Point. In Addition to the AOS Service, also check the user account under which the Batch runs. This account Needs permission to the Folders/Network path as well.

  • UmesH@ Profile Picture
    810 on at

    Hi Martin,

    If i extends class from RunBase it's working fine, but i have to schedule Batch job.

  • Verified answer
    Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at

    Testing it in job proves nothing for reasons explained above. Change your testing procedure to test these things before trying it in batch:

    • Execution in X++ on server
    • Execution in CIL (which is always on server). For example, you can create a menu item pointing to SysOperationsServiceController, set enum parameter to SysOperationsExecutionMode::Synchronous and pass the class and method name with your code in Parameters.

    Most likely your problem isn't really related to batch and you'll be able to reproduce it in this way. Avoid batch will also make your debugging easier.

  • Verified answer
    UmesH@ Profile Picture
    810 on at

    Hi Martin,

    I have followed you step for the scheduling RunBaseBatch Job and it's correct. but from my side there was a issue and I have solved it by changing that file path like below.

    for getting the file from the server I have to use file path like this "\\\\ServerName\\Folder1\\Folder2\\FileName".

    After doing this I am able to read the csv file data.

    Thanks for your Answer.

  • Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at

    Aha, so the first thing I suspected was indeed wrong - the file didn't exist in the local path "C:\test\File1.csv" on AOS.

    By the way, you could use @ to avoid escaping backslashes, as you did originally.

  • UmesH@ Profile Picture
    810 on at

    Hi Martin,

    yes file was there in AOS server, but I am not able to read data from csv file I will use @ sign to avoid escaping backslashes. After that I have used "\\\\ServerName\\Folder1\\Folder2\\FileName" this format and it's working fine now.

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