dataport based on temporay table
AST
Member Posts: 108
Hi,
I have dataport based on temporary table - it works, but I need something more. I need to export only choosen set of fields from Dataport fields. Elements (fields) on set depends on one value in this temporary table, e.g.
Dataport fields
f1
f2
.
.
.
fn
if f1 = value 1 then
"export fields: f2,f3,f5"
if f1 = value 2 then
"export fields: f6,f8,f10"
......
I have dataport based on temporary table - it works, but I need something more. I need to export only choosen set of fields from Dataport fields. Elements (fields) on set depends on one value in this temporary table, e.g.
Dataport fields
f1
f2
.
.
.
fn
if f1 = value 1 then
"export fields: f2,f3,f5"
if f1 = value 2 then
"export fields: f6,f8,f10"
......
0
Comments
-
And your question is?0
-
My question is How to do this. Can I select fileds to export with C/AL?0
-
Can you do it with C/AL sure.
Do you want this selection at run time?
Post your dataport. Need more information.0 -
Just a suggestion.
Why not pass it to a recordref and use the fieldref and do your exporting manipulation.Navision noob....0 -
Yes, I need it at run time - I need selection for each record depends on one value ("Transfer Type") in this record.Do you want this selection at run time?
That,s my dataportOBJECT Dataport 50000 Export Transfer File { OBJECT-PROPERTIES { Date=08-11-07; Time=10:03:42; Modified=Yes; Version List=; } PROPERTIES { Import=No; FieldStartDelimiter=<None>; FieldEndDelimiter=<None>; FieldSeparator=|; UseReqForm=Yes; } DATAITEMS { { PROPERTIES { DataItemTable=Table2000000026; OnPreDataItem=BEGIN TransferFileBuffer.RESET; SETRANGE(Number,1,TransferFileBuffer.COUNT); END; OnAfterExportRecord=BEGIN IF Number = 1 THEN BEGIN TransferFileBuffer.FIND('-'); END ELSE TransferFileBuffer.NEXT; END; } FIELDS { { 1 ;10 ;TransferFileBuffer."Transfer Type" } { 12 ;200 ;TransferFileBuffer.Title } { 213 ;7 ;TransferFileBuffer.CIF } { 221 ;30 ;TransferFileBuffer."Bank account" } ....................................................................... } } } REQUESTFORM { PROPERTIES { Width=9020; Height=3410; } CONTROLS { } } CODE { VAR TransferFileBuffer@1170000 : TEMPORARY Record 60002; i@1170001 : Integer; text@1170002 : Text[30]; PROCEDURE FillTempTable@1170001(VAR Buffer@1170000 : TEMPORARY Record 60002); BEGIN Buffer.RESET; IF Buffer.FIND('-') THEN REPEAT TransferFileBuffer := Buffer; TransferFileBuffer.INSERT(FALSE); UNTIL Buffer.NEXT = 0; END; BEGIN END. } }0 -
I'm not sure what do you mean...Why not pass it to a recordref and use the fieldref and do your exporting manipulation.
When I pass it to a recordref I also have to select a set to export.
Could you please explain your point?0 -
you will have to do it manually (write to a file with yourself) by using CurrFile variable's functions0
-
You can also use a set of global temporary variables to store the fields you want to export. This would allow you to continue using the Request Form and the file dialog functionality of the Dataport.
You can define three variables called column1, column2 and column3, of type text. These would be the SourceExpressions in your Field Designer.
Then you can add the following code to your Dataport:Integer - OnBeforeExportRecord() IF TransferFileBuffer."Transfer Type" ='Odd' THEN BEGIN column1 := FORMAT(TransferFileBuffer.F2); column2 := FORMAT(TransferFileBuffer.F3); column3 := FORMAT(TransferFileBuffer.F5); END ELSE BEGIN column1 := FORMAT(TransferFileBuffer.F6); column2 := FORMAT(TransferFileBuffer.F8); column3 := FORMAT(TransferFileBuffer.F10); END;
Assuming that we have this table:OBJECT Table 60002 Transfer { OBJECT-PROPERTIES { Date=08-11-07; Time=16:51:44; Modified=Yes; Version List=; } PROPERTIES { } FIELDS { { 1 ; ;F1 ;Code10 } { 2 ; ;Transfer Type ;Text30 } { 3 ; ;F2 ;Text30 } { 4 ; ;F3 ;Decimal } { 5 ; ;F10 ;Integer } { 6 ; ;F5 ;Decimal } { 7 ; ;F6 ;Integer } { 8 ; ;F7 ;Text30 } { 9 ; ;F8 ;Code10 } } KEYS { { ;F1 ;Clustered=Yes } } FIELDGROUPS { } CODE { BEGIN END. } }
Our Dataport would look like this:OBJECT Dataport 50000 Export Transfer File { OBJECT-PROPERTIES { Date=08-11-07; Time=16:55:56; Modified=Yes; Version List=; } PROPERTIES { Import=No; FieldStartDelimiter=<None>; FieldEndDelimiter=<None>; FieldSeparator=|; UseReqForm=Yes; OnInitDataport=BEGIN FillTempTable(TransferFileBuffer); END; } DATAITEMS { { PROPERTIES { DataItemTable=Table2000000026; OnPreDataItem=BEGIN TransferFileBuffer.RESET; SETRANGE(Number,1,TransferFileBuffer.COUNT); END; OnBeforeExportRecord=BEGIN IF TransferFileBuffer."Transfer Type" ='Odd' THEN BEGIN column1 := FORMAT(TransferFileBuffer.F2); column2 := FORMAT(TransferFileBuffer.F3); column3 := FORMAT(TransferFileBuffer.F5); END ELSE BEGIN column1 := FORMAT(TransferFileBuffer.F6); column2 := FORMAT(TransferFileBuffer.F8); column3 := FORMAT(TransferFileBuffer.F10); END; END; OnAfterExportRecord=BEGIN IF Number = 1 THEN BEGIN TransferFileBuffer.FIND('-'); END ELSE TransferFileBuffer.NEXT; END; } FIELDS { { 1 ;10 ;column1 } { 12 ;200 ;column2 } { 213 ;7 ;column3 } } } } REQUESTFORM { PROPERTIES { Width=9020; Height=3410; } CONTROLS { } } CODE { VAR TransferFileBuffer@1170000 : TEMPORARY Record 60002; i@1170001 : Integer; text@1170002 : Text[30]; column1@1102601000 : Text[30]; column2@1102601001 : Text[30]; column3@1102601002 : Text[30]; PROCEDURE FillTempTable@1170001(VAR Buffer@1170000 : TEMPORARY Record 60002); BEGIN Buffer.RESET; IF Buffer.FIND('-') THEN REPEAT TransferFileBuffer := Buffer; TransferFileBuffer.INSERT(FALSE); UNTIL Buffer.NEXT = 0; END; BEGIN END. } }“This posting is provided "AS IS" with no warranties, and confers no rights.”0 -
Thanks a lot, it would be a good idea, but my sets have different number of elements, so it can't workYou can also use a set of global temporary variables to store the fields you want to export.
0 -
I could create several dataports - based on the same temporary table but with different dataport fileds. Then I could do something like that
if val1 run Dataport1 if val2 run Dataport2 ......
but how to write several dataports to the same file not override it? :-k0 -
Or maybe I could write one dataport to regular file and the rest of dataports to temporary file and then copy each temporary file to the end of regular file?
It is good idea?
Or maybe I just should write to file manually? I have from 19 to 32 fields for each record and I need sparator '|' between fields. #-o0 -
Would defining a single line global variable of type Text255 help? Your code would look like this:
Integer - OnBeforeExportRecord() IF TransferFileBuffer."Transfer Type" ='Odd' THEN BEGIN line:= FORMAT(TransferFileBuffer.F2) + '|' + FORMAT(TransferFileBuffer.F3) + '|' + FORMAT(TransferFileBuffer.F5) END ELSE BEGIN line:= FORMAT(TransferFileBuffer.F6) + '|' + FORMAT(TransferFileBuffer.F8); END;
where line is the SourceExpression for your only entry in Field Designer.
You may need to do additional padding using the PADSTR(String, Length [, FillCharacter]) function, if you need that.“This posting is provided "AS IS" with no warranties, and confers no rights.”0 -
That's what I try to avoid - becouse I have a lot of fields to export.Would defining a single line global variable of type Text255 help?0 -
I have one other proposal. This won't work if you have to sort your output based on a field other than TransferType, but for the sake of completion I will mention it.
You can have two DataItems on the Xml Port. They would have different DataItemTableView properties, filtering on the TransferType field (doing the same thing with the if TransferType = ... statement we used before). Since each DataItem can have a different set of DataPort Fields list, the only thing you need to do is to set the DataItemSeparator property to <NewLine>, so that output will not have a blank line in between.
Assuming that TransferType can be 'Odd' or 'Even' only, I defined two DataItems with corresponding filters. (I also removed the temporary table from code.)
The problem with this is the two RequestForm tabs you get in addition to Options tab. But if you are able to suppress the RequestForm, it should not be a problem.
Code looks like this, then:OBJECT Dataport 50000 Export Transfer File { OBJECT-PROPERTIES { Date=11-11-07; Time=00:41:50; Modified=Yes; Version List=; } PROPERTIES { Import=No; FieldStartDelimiter=<None>; FieldEndDelimiter=<None>; FieldSeparator=|; DataItemSeparator=<NewLine>; UseReqForm=Yes; OnInitDataport=VAR transfer@1102601000 : Record 60002; BEGIN END; } DATAITEMS { { PROPERTIES { DataItemTable=Table60002; DataItemVarName=OddTransfers; DataItemTableView=WHERE(Transfer Type=CONST(Odd)); } FIELDS { { ; ;F2 } { ; ;F3 } { ; ;F5 } } } { PROPERTIES { DataItemTable=Table60002; DataItemVarName=EvenTransfers; DataItemTableView=WHERE(Transfer Type=CONST(Even)); } FIELDS { { ; ;F6 } { ; ;F8 } } } } REQUESTFORM { PROPERTIES { Width=9020; Height=3410; } CONTROLS { } } CODE { BEGIN END. } }“This posting is provided "AS IS" with no warranties, and confers no rights.”0
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
- 610 NAV Courses, Exams & Certification
- 1.9K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 251 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
