How Set dynamic dataports in code

rvirrvir 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

Comments

  • rvirrvir Member Posts: 5
    Any idea ??? ]
    (*,)
  • krikikriki Member, Moderator Posts: 9,110
    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!


  • rvirrvir Member Posts: 5
    Thanks for idea kriki
Sign In or Register to comment.