problem in dataport

vikas
Member Posts: 46
Hi,
I have a query regarding dataport.
I have a text(csv) file which looks like this
No,Name,Address
Item No,Quantity,Price
Now i want to push 1st line to the customer table & 2nd line to the item table.
Please help me in this regard.
Thanks,
Vikas S. Shettar
I have a query regarding dataport.
I have a text(csv) file which looks like this
No,Name,Address
Item No,Quantity,Price
Now i want to push 1st line to the customer table & 2nd line to the item table.
Please help me in this regard.
Thanks,
Vikas S. Shettar
0
Comments
-
I take it the second line is information on the selling price of an Item for the imported customer?
If that is the case, I would do the following:
Declare 7 Variables in your Dataport:
gvImportField1 Text
gvImportField2 Text
gvImportField3 Text
gvImportLineCounter Integer
gvCustomer Record Customer
gvSalesPrice Record Sales Price
gvImportCustNo Text
Declare your Dataport "DataItem" to be either Customer or Item, but modify the DataItem properties to:
AutoUpdate: False
AutoInsert: False
AutoReplace: False
Assign these 3 fields as your DataPortFields. What will happen is, when importing, gvImportField1 will then either contain a Customer No OR Item No.
Now, in the OnAfterImportRecord trigger of your DataItem, you must do the following:
IF gvImportCounter = 1 THEN BEGIN
gvImportedCustNo := ImportField1;
IF NOT gvCustomer.GET(gvImportField1) THEN BEGIN //Insert Customer
gvCustomer.INIT;
gvCustomer."No." := COPYSTR(gvImportField1, 1, 20);
gvCustomer.VALIDATE(Name, COPYSTR(gvImportField2, 1, 30));
gvCustomer.Address := gvImportField3;
gvCustomer.INSERT;
END;
gvImportCounter += 1;
END
ELSE IF gvImportCounter = 2 THEN BEGIN
gvSalesPrice.RESET;
gvSalesPrice.SETRANGE(gvSalesPrice."Sales Type"::Customer);
gvSalesPrice.SETRANGE(gvSalesPrice."Sales Code", gvImportCustNo);
gvSalesPrice.SETRANGE(gvSalesPrice."Item No.", gvImportField1);
IF NOT gvSalesPrice.FIND('-') THEN BEGIN //Insert Sales Price
gvSalesPrice.INIT;
gvSalesPrice."Item No." := COPYSTR(ImportField1, 1, 20);
gvSalesPrice."Sales Type" := gvSalesPrice."Sales Type"::Customer;
gvSalesPrice."Sales Code" := gvImportCustNo;
gvSalesPrice.INSERT;
END;
gvImportCounter := 1;
END;0 -
but sir,
i have to insert records simaltanously into two tables. 1st line into customer table and 2nd line into item table.
can u tell me how??
because i am a fresher....0 -
The Code above works fine when you replace the part "gcSalesPrice" with "Item", where you insert the Data in the Itemtable! You know, how to do this?
What do you mean with simultaniously? You can only read one line of the file per step! And with the counter you decide if you have to insert a customer or a item.
Greetings,
Frank0 -
sir...
but it is not entering into the first loop itself.0 -
Define some global variables that contain the fields in the file you are reading. Use the table (virtual table "Number" should be used off cause
*edited*)Standardtext as your dataitem. In the properties set autosave and autoupdate to NO. Use the global variables as dataport fields. Now on the OnAfterImportRecord you will make the code that updates the Customer AND the Item table with the data that you have read into the global variables.
Best regards
Tommy0 -
Sorry vikas, I forgot something in the code...
In the PreDataItem code, you must enter another line of code...
gvImportCounter := 1;
This will ensure that the first section of code is executed...
Without this line of code, the Dataport will start to run without a value in the gvImportCounter variable - thus not executing the first section of code.0
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