BC 21 import multiple xmlport with dynamic filesnames

Noeline
Member Posts: 54
Hi
We have written a codeunit to import via xmlports that have been defined. RequestPage is set to false, and and initial FileName is specified in the properties of the XMLPorts. The codeunit reads the import folder and imports the files, one at a time. Our problem is that although we have set the FileName on the OnInitXML and OnPreXML, the system stills pops up a window for each file asking the user the Choose the file.
If there are 20 or 50 files this user input becomes problematic. Is it possible to avoid the user having to choose a file each time, and if so, how?
Regards - Noeline
We have written a codeunit to import via xmlports that have been defined. RequestPage is set to false, and and initial FileName is specified in the properties of the XMLPorts. The codeunit reads the import folder and imports the files, one at a time. Our problem is that although we have set the FileName on the OnInitXML and OnPreXML, the system stills pops up a window for each file asking the user the Choose the file.
If there are 20 or 50 files this user input becomes problematic. Is it possible to avoid the user having to choose a file each time, and if so, how?
Regards - Noeline
0
Best Answer
-
A little change in the procedure
local procedure ReadFiles(DirPath: Text; pXmlPort: XmlPort "Your XMLPort") var fileMgt: Codeunit "File Management"; NameValBuf: Record "Name/Value Buffer" temporary; xFile: File; InStr: InStream; begin if fileMgt.ServerDirectoryExists(DirPath) then begin fileMgt.GetServerDirectoryFilesList(NameValBuf, DirPath); if NameValBuf.FindSet() then repeat xFile.Open(NameValBuf.Name); xfile.CreateInStream(InStr); Clear(pXmlPort); pXmlPort.SetSource(InStr); pXmlPort.Filename := NameValBuf.Name; pXmlPort.Import(); xFile.Close(); until NameValBuf.Next() = 0; end else Message('Directory %1, doesn''t exists', DirPath); end;
1
Answers
-
Hello @ftornero
I forgot to mention, this is on-prem. The UploadIntoStream method opens a dialog asking the user to choose the file, and I don't find a way around it. My workaround has been to import with CSV Buffer instead. This does not open a dialog and uses the path and file variables, but it has certain limitations. I would prefer the xmlports if I could find a way to do a silent upload.
Regards - Noeline0 -
Hello @Noeline,
You need to do something like this:local procedure ReadFiles(DirPath: Text; pXmlPort: XmlPort "Your XmlPort") var fileMgt: Codeunit "File Management"; NameValBuf: Record "Name/Value Buffer" temporary; xFile: File; InStr: InStream; begin if fileMgt.ServerDirectoryExists(DirPath) then begin fileMgt.GetServerDirectoryFilesList(NameValBuf, DirPath); if NameValBuf.FindSet() then repeat xFile.Open(NameValBuf.Name); xfile.CreateInStream(InStr); pXmlPort.SetSource(InStr); pXmlPort.Import(); until NameValBuf.Next() = 0; end else Message('Directory %1, doesn''t exists', DirPath); end;
Regards0 -
A little change in the procedure
local procedure ReadFiles(DirPath: Text; pXmlPort: XmlPort "Your XMLPort") var fileMgt: Codeunit "File Management"; NameValBuf: Record "Name/Value Buffer" temporary; xFile: File; InStr: InStream; begin if fileMgt.ServerDirectoryExists(DirPath) then begin fileMgt.GetServerDirectoryFilesList(NameValBuf, DirPath); if NameValBuf.FindSet() then repeat xFile.Open(NameValBuf.Name); xfile.CreateInStream(InStr); Clear(pXmlPort); pXmlPort.SetSource(InStr); pXmlPort.Filename := NameValBuf.Name; pXmlPort.Import(); xFile.Close(); until NameValBuf.Next() = 0; end else Message('Directory %1, doesn''t exists', DirPath); end;
1
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K 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
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions