Replacing Characters in a Dataport
ta5
Member Posts: 1,164
Hi
I want to replace some characters in a dataport. The field delimiters are ", but this character also occurs in the field values itself. Needless to say, this causes an error then. Changing the import file is not an option.
So my idea is, OnPreDataPort to loop sequential through the File, save it and go on with the Dataport. Anyway, it should be in the same step as the dataport itself and should be transparent to the user.
Is this possible and/or somebody has a better idea? Maybe edit the line on the trigger OnBeforeImportRecord?
Best regards
Thomas
I want to replace some characters in a dataport. The field delimiters are ", but this character also occurs in the field values itself. Needless to say, this causes an error then. Changing the import file is not an option.
So my idea is, OnPreDataPort to loop sequential through the File, save it and go on with the Dataport. Anyway, it should be in the same step as the dataport itself and should be transparent to the user.
Is this possible and/or somebody has a better idea? Maybe edit the line on the trigger OnBeforeImportRecord?
Best regards
Thomas
0
Answers
-
Put field delimiters to <None>.
Import the fields in global variables.
In the OnAfterImportRecord:txtVariable := DELCHR(txtVariable,'<>','"');
This deletes the " in the beginning and the end of the string.Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
I would use a codeunit and do the following, rebuild the file by reading it into a varaible and writing it back to a new file then run the dataport on the clean file.
You will need to use the combination of the 3 chars, then remove the invalid , and " from the selected string (Field)
This only works if the file has comma's and text delimiters ","
This is from memory so not tested and may need adjustment
CLEAR(OldFile);
OldFile.TEXTMODE := TRUE;
OldFile.OPEN(FileName);
WHILE OldFile.POS <> OldFile.LEN DO BEGIN
//Read the line into a variable LineDetail
OldFile.READ(LineDetail);
CLEAR(TempDetail);
//Use STRPOS to find your string ","
WHILE STRPOS(LineDetail,'","') > 0 BEGIN
CLEAR(TempStr);
Position := STRPOS(LineDetail,'","');
//Cut the Field from the LineDetail
TempStr := COPYSTR(LineDetail,1,Position-1);
//Trim the lineDetail
LineDetail := COPYSTR(LineDetail,Position+3);
//Remove Invalid text " and ,
TempStr := DELCHR(TempStr,'=','"');
TempStr := DELCHR(TempStr,'=',',');
//Build the New Line
IF TempDetail <> '' THEN
TempDetail := TempDetail +',' +TempStr
ELSE
TempDetail := TempStr;
END;
//We still may have some text to add and the comma for the last field
//Remove Invalid text " and ,
LineDetail := DELCHR(LineDetail,'=','"');
LineDetail := DELCHR(LineDetail,'=',',');
//Build the New Line
IF TempDetail <> '' THEN
TempDetail := TempDetail +',' LineDetail
ELSE
TempDetail := LineDetail;
NewFile.WRITE(TempDetail);
END;
Close your two Files and run your dataport
So the string "This string is 3" long, I think","Nah it ain,t"
Will become This string is 3 long I think,Nah it aint
Phew think that covers it! 8)Analyst Developer with over 17 years Navision, Contract Status - Busy
Mobile: +44(0)7854 842801
Email: david.cox@adeptris.com
Twitter: https://twitter.com/Adeptris
Website: http://www.adeptris.com0 -
I have not used INSTREAM, but you might be able to open the file then use CONVERTSTR(MyStream,",","~");
This should convert from comma seperated "," to tilde "~". then just change the seperator in the dataport.
Not sure how to code it, without doing it, so its just an Idea!
The is a common problem so a solution would be worth posting to Tips and Tricks
Analyst Developer with over 17 years Navision, Contract Status - Busy
Mobile: +44(0)7854 842801
Email: david.cox@adeptris.com
Twitter: https://twitter.com/Adeptris
Website: http://www.adeptris.com0 -
This may be a silly question, but could you consider or are you able to switch to fixed length?Kristopher Webb
Microsoft Dynamics NAV Developer0 -
No simple solution if you cannot get the file delimeter changed, and you say that is not an option.
So is the file text and comma delimited?
"Mr","Fred Flintstone","Cave 1,The Mound","Bedrock","$1,200.00"
Use CHANGESTR replace the "," with a Tilde ~ and then remove the " and ,
Or is it only text qualifed when there is a quote or comma in the string?
Mr,Fred Flintstone,"Cave 1,The Mound",Bedrock,"$1,200.00"
Use STRPOS this ," to find the start point and ", the end and then remove the , or the " and rebuild.Analyst Developer with over 17 years Navision, Contract Status - Busy
Mobile: +44(0)7854 842801
Email: david.cox@adeptris.com
Twitter: https://twitter.com/Adeptris
Website: http://www.adeptris.com0 -
I've managed it now like this.
OnPreDataport: Replace all " in the file with another special character, except of the " in the middle of a field. Actually as David suggested. Store in a new file.
Then use the new file in the dataport (Currdataport.file...).
Thank you for your help and ideas!
Thomas0
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 611 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 253 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions