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 :
Finance | Project Operations, Human Resources, ...
Unanswered

Insert Data into Table

(0) ShareShare
ReportReport
Posted on by 492

Hello Team,

We have a requirement to insert data into table. Our data is in format as below

XYZ              123          Senthil          Tamil Nadu           India

                                     Yadav

We have to insert record Senthil Yadav same as shown in the above example in a memo field (DocuRef table--> Notes Field) and we have written the code as below: 

if (fName)
{
file = new TextIo(fName, 'r');
if (file.status())
{
throw error("@SYS52680");
}
file.inRecordDelimiter('\r\n');
file.inFieldDelimiter ('\t');

}

the logic we applied was for \n as new line but we need to change it for accepting the record Senthil Yadav. Can anyone please let us know how we can implement this in X++ Code.

Thank You.

I have the same question (0)
  • Martin Dráb Profile Picture
    237,882 Most Valuable Professional on at

    It seems that you're talking about reading data from a text file.

    Unfortunately the information about the file format isn't sufficient. Does the file contain just a single record? If there are more, does every record have two lines? If so, you'll simply need to read data from two lines before inserting data to a table. Or do some records have a single line and some two lines? If so, you need decide how you'll identify each case.

    One obvious problem with your code it that you never call read() method. You should do something like this:

    container data;
    #File
    
    if (fName)
    {
    	file = new TextIo(fName, #io_read);
    	if (!file)
    	{
    		throw error("@SYS52680");
    	}
    	
    	file.inRecordDelimiter(#delimiterCRLF);
    	file.inFieldDelimiter (#delimiterTab);
    	
    	data = file.read();
    	
    	while (file.status() == IO_Status::Ok)
    	{
    		// Here you'll extract values from the container
    	
    		data = file.read();
    	}
    }

    By the way, please use Insert > Insert Code (in the rich-formatting view) to paste source code, as I did. It preserves line indentation, which makes code much easier to read.

  • Senthil Yadav Profile Picture
    492 on at

    Hello Martin,

    Thanks for your inputs, We have the data as below:

    995 9951006389 "Flat No123 SalesInvoice 1 0

    Sambhaji Colony

    Abad 431003

    Phone:021-39921126

    India

    VAT:123456789"

    995 9951006390 "Flat No546 SalesInvoice 1 0

    Tuticorin

    Tirunelveli 627702

    Phone:0462-56310675

    India

    VAT:533416006"

    Third Column here starts with " and also ends with ". we have a requirement to enter these kind of records where the column can be of 4 lines or 5 lines or any no of lines.

    Can you please let us know how can we implement the same.

    Thank You.

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

    One option is reading lines one by one and interpret them by yourself.

    Another is using a more powerful API that isn't limited to individual lines. (I don't have any concrete recommendation, but you might be able to find something useful in this list, for example.)

    Even the data import/export framework in AX 2012 should be able to handle it, because multiline values are possible in CSV and I believe that DIXF in AX 2012 is able to import them.

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 565 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 450 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans