Hi everyone, this is my first post here in NAV forum. I am working on a request from client, where they want to import data from a txt file when they click on a button in a page. When doing the import, system should check if more than one record appears with same column A and column B in the same txt file, then prompt an error message.
I have achieved the importing function through a command button in the page, basically in the OnPush event of the button i writes DATAPORT.RUNMODAL. But when comes to detecting records with same column A and B within the txt file, i found no relevant information after searching online for hours. Is there any sample code that i can refer or any properties that i need to set?
Thanks for helping.
Edit: The txt file has no column header, use coma delimiter, such as row1column1,row1column2,row1column3…row1column9 , then next line
A good way to make the format of the dataport work for you, is to start by exporting data. And the files you want to import look like the one you export, then you’re almost there! Especially if it’s your first dataport.
Have you run the dataport with the debugger. Are you able to see if any data gets imported?
Hi Erik, glad to receive reply, thanks! And how do you know its my first dataport haha
To asnwer your question, yes i do see data gets imported. I have deleted and imported the data many times to test out my C/AL code to detect duplicate rows between txt data and existing data in table. This is another part of the request that i have achieved yesterday
But today i cant get the code works to detect duplicate row within the txt file itself, and there is not much relevant resource that i can find online…may i know have you done this kind of request before?
PS: i have been trying this in the OnPreDataItem & OnBeforeImportRecord event in the Dataport
Did you check the settings to automatically insert/update, or are you doing it by code in the dataport? If yes, which triggers?
A good way to find out exactly what is going on, is the debugger. The challenge with dataport (and many other objects) that it has a lot of different tiggers, and which ones to use? Putting “Dummy := Dummy;” into the triggers allow you to see the order and which triggers are executed.
Actually i have found out the order of the triggers previously by putting MESSAGE(TriggerName) in each trigger.
And yes i did set the AutoSave property to Yes. I set it in the Data Item’s properties window, not by code. There is only 1 data item in DataPort Designer at the moment.
Actually I am stuck at finding code sample to check data duplication.
Hi all, i have sorted this out by putting Record.GET(ColumnA, ColumnB) inside IF statement at OnAfterImportRecord trigger. If the IF statement detected the the result as True, then use ERROR to stop the importing process.