Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Unanswered

Insert Data into Table

Posted on by 490

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.

  • Martin Dráb Profile Picture
    Martin Dráb 230,214 Most Valuable Professional on at
    RE: Insert Data into Table

    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.

  • Senthil Yadav Profile Picture
    Senthil Yadav 490 on at
    RE: Insert Data into Table

    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
    Martin Dráb 230,214 Most Valuable Professional on at
    RE: Insert Data into Table

    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.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans