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)

How to Import data from a CSV file to a Table in Form

(0) ShareShare
ReportReport
Posted on by

Hi All , 

I have a table called Empl_Temp .  

I have created a .CSV file and have inserted some data in it.

In my form I have added File Open Dialog then through this ll select the .CSV file and when the Update is Clicked I want the data in .CSV file to get Populated in the table Empl_Temp . 

Please Let me know How Could I do this.

Till Now I have Performed all the necessary actions required to select a .CSV through an File Open Dialog.

Regards , 

Nishath Salman N.

*This post is locked for comments

I have the same question (0)
  • Ali Zaidi Profile Picture
    4,657 on at

    Hi, I used following code snippet for reading CSV. You can use IO framework / api and container to perform this task.

    tech.alirazazaidi.com/reading-csv-files-in-dynamics-ax-2012

  • Community Member Profile Picture
    on at

    Hi am using Method :

    void importFromTextFile()

    {

           SysOperationProgress    simpleProgress;

           ;

           permission      = new fileIOpermission(sfileName,#io_read);

           permission.assert();

           textIO          = new TextIO(sfileName,#io_read);

           textIO.inFieldDelimiter("|");

           textIO.inRecordDelimiter('\n');

           simpleProgress  = SysOperationProgress::newGeneral(#AviUpdate,"Import is in progress",100);

           startLengthyOperation();

           while(textIO.status() == IO_Status::Ok)

           {

                           c  = textIO.read();

                           if(conLen(c) > 1)

                           {

                                   setPrefix(this.caption());

                           importTable.clear();

                                   importTable. EmplId                = conpeek(c,1);

                                   importTable.New_EmplName                 = conpeek(c,2);

                                   importTable.New_FirstName   = conpeek(c,3);

                                   importTable.New_LastName                 = conpeek(c,4);

                                   importTable.New_Email = conpeek(c,5);

                                   importTable.New_Telephone = conpeek(c,6);

                                   importTable.New_Designation = conpeek(c,7);

                                   importTable.New_DOB = conpeek(c,8);

                                   importTable.update();

                                   info("Record Updated Successfully !!!");

               }

                   }

           endLengthyOperation();

    }

    But it seems like when I run the program ,  Control Flow  only is not coming to this method coz I have included one (info"") statement which is not getting executed at all.

    I have written this method in a class and in my form I have a button called Updated . and in its clicked event , I am calling some methods and it is one among them .

    Please let m know what's wrong in it

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

    If your method isn't called at all, showing its code won't help, because the problem is somewhere else. You have to look at code that should call this method. The debugger will help you to understand what's going on.

  • Community Member Profile Picture
    on at

    MArtin please let me know where should I call this method

  • Ali Zaidi Profile Picture
    4,657 on at

    You can call this class object in AX job or click method / event of button.

  • Community Member Profile Picture
    on at

    I have called the method using the Class Object in the Click event of the button.  Still don't no why it s not getting executed .

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

    You should call it using using a class and menu item button, therefore you wouldn't need any code in clicked() method. Clicked() method is not a good place for business logic. You already refer to SysOperationProgress, so why don't you call your logic through SysOperation framework? It will switch execution to server, allow you to use CIL, do parameter synchronization for you, allow you to run import in batch and so on.

    Nevertheless if you want to know what's wrong in your current code, you would have to show it to us. We can't read your mind; you have to write information down.

  • Community Member Profile Picture
    on at

    I have already given u MArtin the entire Code that m processing. just that I am really confused like how should I call those methods that I have created . Coz I tried calling them through the Click event of the Button.

    If you are getting Irritated then I ll never ask you any thing . Thanks for your help so far

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

    You gave us a piece of code and said that it's not called at all. It means that its content is irrelevant in the moment.

    Then you said that you have a click event where you are calling some methods and that you have called the method using the Class Object.

    Unfortunately some methods is not enough information for me to tell you where your bug lies. Do you believe that it's enough?

    I'm spending my time trying to help you, instead of making money, helping somebody else, having a walk or who know what. But I can't do much if you don't do your part and don't give us information that we ask for. Time is limited and it's in your best interest to allow respondents to use time that they dedicate to your question in a productive manner, instead of trying to get basic information from you.

  • Karen Tabatini Profile Picture
    20 on at

    Hello Nishath!

    I'm not sure if I understood your problem, but let's see if I can help you.

    1) Write a class with a static main method and call your bussiness method (for exemple: importFromTextFile) from this one.

    1452.menu-item.JPG

    2) Create an action menu item and call your class

    1452.menu-item.JPG

    3) Use menu item on the form. Note: You don't need to override any method, the engine will automatically call the main method in you class. 

    5165.form.JPG

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