How Set dynamic dataports in code

rvir
Member Posts: 5
I have two different dataport, both import data to the same tables but in different way.
In loop for customer I call up function to import data.
In this moment I have two function, they are almost identically but the variable signed to dataport is different.
Code for loop looks like:
CustomerRec.Reset;
If CustomerRec.FIND('-') THEN BEGIN
REPEAT
IF CustomerRec.CustomerNo = 1 THEN
ImportDataFunction(CustomerRec);
IF CustomerRec.CustomerNo = 2 THEN
ImportDataFunction2(CustomerRec);
UNTIL CustomerRec.NEXT=0;
END;
Code in both function (ImportDataFunction AND ImportDataFunction2) looks that:
Name DataType Subtype Length
ImportDataportVariable Dataport Import_data
ret Integer
EXISTS('FilePath');
ret := SHELL('FilePath',
Rec."Error Directory", Rec."Output Directory", '_list.txt');
IF EXISTS(CustRec."Output Directory" + '\_list.txt') THEN BEGIN
ImportDataportVariable.IMPORT := TRUE;
ImportDataportVariable.FILENAME := CustRec."Output Directory" + '\_list.txt';
ImportDataportVariable.SetCustomer(CustRec."Customer Name");
ImportDataportVariable.RUN();
IF EXISTS(CustRec."Output Directory" + '\_list.txt') THEN
ERASE(CustRec."Output Directory" + '\_list.txt')
END;
In second function I have changed only variable ImportDataportVariable to different dataport.
Now I wont create only one function instead of two.
I have table with settings where I set for each I need Customer, specific dataport. That In loop for concrete customer I know which dataport I must use.
But unfortunetly I have know idea :-k how do that, in my function, that the variable Import_data should be dynamic change??
Do you have idea for that ?? Thanks
In loop for customer I call up function to import data.
In this moment I have two function, they are almost identically but the variable signed to dataport is different.
Code for loop looks like:
CustomerRec.Reset;
If CustomerRec.FIND('-') THEN BEGIN
REPEAT
IF CustomerRec.CustomerNo = 1 THEN
ImportDataFunction(CustomerRec);
IF CustomerRec.CustomerNo = 2 THEN
ImportDataFunction2(CustomerRec);
UNTIL CustomerRec.NEXT=0;
END;
Code in both function (ImportDataFunction AND ImportDataFunction2) looks that:
Name DataType Subtype Length
ImportDataportVariable Dataport Import_data
ret Integer
EXISTS('FilePath');
ret := SHELL('FilePath',
Rec."Error Directory", Rec."Output Directory", '_list.txt');
IF EXISTS(CustRec."Output Directory" + '\_list.txt') THEN BEGIN
ImportDataportVariable.IMPORT := TRUE;
ImportDataportVariable.FILENAME := CustRec."Output Directory" + '\_list.txt';
ImportDataportVariable.SetCustomer(CustRec."Customer Name");
ImportDataportVariable.RUN();
IF EXISTS(CustRec."Output Directory" + '\_list.txt') THEN
ERASE(CustRec."Output Directory" + '\_list.txt')
END;
In second function I have changed only variable ImportDataportVariable to different dataport.
Now I wont create only one function instead of two.
I have table with settings where I set for each I need Customer, specific dataport. That In loop for concrete customer I know which dataport I must use.
But unfortunetly I have know idea :-k how do that, in my function, that the variable Import_data should be dynamic change??
Do you have idea for that ?? Thanks
0
Comments
-
Any idea ??? ]
(*,)0 -
You can use "DATAPORT.RUNMODAL(Number [, ReqWindow] [, Record])".
But in the properties of the dataports, you need to set it is for import or export.
With this statement, you can just change "Number" to one of the dataports.
If you need to send other parameters, there are several ways to do it.
-Use a singleinstance codeunit to accept a parameter from the calling object and send the parameter to the dataport by a call from the dataport. This is the cleanest way. See also http://www.mibuso.com/howtoinfo.asp?FileID=9 for info on how to create/use a singleinstance codeunit.
-Write in some real table the parameters that the dataport can read. This is a way I would avoid because it starts a transaction.
-Apply the parameters as filters to some fields. In the dataport you can read the filters, put them in the needed fields and remove the filters.Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
Thanks for idea kriki0
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