Objective of the task is to pick up N(for example 5,10,100, etc..) records from csv File and put in an array. This can also be generic, you can post those records to web API OR perform any operations as per your requirement.
Steps:
- Count total number of rows(records) in a file. [use component tFileRowCount].
- Define 3 variables. one for total count of records, second for header, third is to limit the records. [use component tSetGlobalVar]
in the screenshot, i have used Header as 1 as the csf file contains Header. Also, you can start from specific records based on this value. Also Limit is set 10. you can take this value from context and configure it as per your needs.
- Apply loops until the variable Header is less than or equals to total row count. [use tLoop, in the condition use Header <= totalRowCount]
- Get the data from delimated file, add Header and Limit variables in the coppresponding place. [use component tFileInputDelimated]
The number in Header skips the number of rows specified in header and the limit extracts the number of rows specified in it.
- For storing those data in an array use component use component tJavaFlex. Define ArrayList in it and store the N items in an array.
In the tJavaFlex Component, an ArrayList is defined first, and all the elements of the csv file are added in this array. And finally this value is set in a global Variable named List.
If you print the value list in next tJava component, you will get the desired result.Output Screenshot:







Comments
Post a Comment