Copy Table
Copy data from a data table
Command availability: IBM RPA SaaS and IBM RPA on premises
Description
Copies all data from a data table, or just its structure, returning it on a new table.
Table structure is, by definition, its rows, columns, and table styles.
Script syntax
IBM RPA's proprietary script language has a syntax similar to other programming languages. The script syntax defines the command's syntax in the script file. You can work with this syntax in IBM RPA Studio's Script mode.
copyTable [--schemaonly(Boolean)] --dataTable(DataTable) (DataTable)=value
Dependencies
The data table that is entered in the Data Table parameter must be previously obtained. Below are some commands that return Data Table variables:
- Open Excel File (
excelOpen
) - Get Excel Table (
excelGetTable
) - Read CSV File (
readCSV
)
Input parameter
The following table displays the list of input parameters available in this command. In the table, you can see the parameter name when working in IBM RPA Studio's Script mode and its Designer mode equivalent label.
Designer mode label | Script mode name | Required | Accepted variable types | Description |
---|---|---|---|---|
Schema only | schemaonly |
Optional |
Boolean |
Enable to copy only the data table structure. |
Data Table | dataTable |
Required |
Data Table |
Source data table used to copy the data and structure. |
Output parameter
Designer mode label | Script mode name | Accepted variable types | Description |
---|---|---|---|
Data Table | value |
Data Table | Returns a new data table with the copy of the data and/or structure of the source table. |
Example
The Copy Table (copyTable
) command is used with the Schema only parameter enabled to copy the structure of the table, and adds only employees over 45 years old to this
new table with a filter.
defVar --name tableValues --type DataTable
defVar --name newTable --type DataTable
defVar --name filterTable --type DataTable
defVar --name age --type String
defVar --name row --type Numeric
defVar --name name --type String
defVar --name position --type String
defVar --name office --type String
defVar --name startDate --type String
getTablesFromHtml --html "<table id=\"example\" class=\"display nowrap dataTable dtr-inline collapsed\" style=\"width: 100%;\" aria-describedby=\"example_info\"><thead><tr><th class=\"sorting sorting_asc\" tabindex=\"0\" aria-controls=\"example\" rowspan=\"1\" colspan=\"1\" style=\"width: 136px;\" aria-sort=\"ascending\" aria-label=\"Name: activate to sort column descending\">Name</th><th class=\"sorting\" tabindex=\"0\" aria-controls=\"example\" rowspan=\"1\" colspan=\"1\" style=\"width: 185px;\" aria-label=\"Position: activate to sort column ascending\">Position</th><th class=\"sorting\" tabindex=\"0\" aria-controls=\"example\" rowspan=\"1\" colspan=\"1\" style=\"width: 85px;\" aria-label=\"Office: activate to sort column ascending\">Office</th><th class=\"dt-body-right sorting\" tabindex=\"0\" aria-controls=\"example\" rowspan=\"1\" colspan=\"1\" style=\"width: 32px;\" aria-label=\"Age: activate to sort column ascending\">Age</th><th class=\"dt-body-right sorting\" tabindex=\"0\" aria-controls=\"example\" rowspan=\"1\" colspan=\"1\" style=\"width: 75px;\" aria-label=\"Start date: activate to sort column ascending\">Start date</th><th class=\"dt-body-right sorting dtr-hidden\" tabindex=\"0\" aria-controls=\"example\" rowspan=\"1\" colspan=\"1\" style=\"width: 0px; display: none;\" aria-label=\"Salary: activate to sort column ascending\">Salary</th></tr></thead><tbody><tr class=\"odd\"><td class=\"dtr-control sorting_1\" tabindex=\"0\" style=\"\">Airi Satou</td><td>Accountant</td><td>Tokyo</td><td class=\"dt-body-right\">33</td><td class=\"dt-body-right\">11/27/2008</td><td class=\"dt-body-right dtr-hidden\" style=\"display: none;\">$162,700</td></tr><tr class=\"even\"><td class=\"sorting_1 dtr-control\" tabindex=\"0\" style=\"\">Angelica Ramos</td><td>Chief Executive Officer (CEO)</td><td>London</td><td class=\"dt-body-right\">47</td><td class=\"dt-body-right\">10/8/2009</td><td class=\"dt-body-right dtr-hidden\" style=\"display: none;\">$1,200,000</td></tr><tr class=\"odd\"><td class=\"dtr-control sorting_1\" tabindex=\"0\" style=\"\">Ashton Cox</td><td>Junior Technical Author</td><td>San Francisco</td><td class=\"dt-body-right\">66</td><td class=\"dt-body-right\">1/11/2009</td><td class=\"dt-body-right dtr-hidden\" style=\"display: none;\">$86,000</td></tr><tr class=\"even\"><td class=\"sorting_1 dtr-control\" tabindex=\"0\">Bradley Greer</td><td>Software Engineer</td><td>London</td><td class=\"dt-body-right\">41</td><td class=\"dt-body-right\">10/12/2012</td><td class=\"dt-body-right dtr-hidden\" style=\"display: none;\">$132,000</td></tr><tr class=\"odd\"><td class=\"sorting_1 dtr-control\" tabindex=\"0\">Brenden Wagner</td><td>Software Engineer</td><td>San Francisco</td><td class=\"dt-body-right\">28</td><td class=\"dt-body-right\">6/6/2011</td><td class=\"dt-body-right dtr-hidden\" style=\"display: none;\">$206,850</td></tr><tr class=\"even\"><td class=\"dtr-control sorting_1\" tabindex=\"0\">Brielle Williamson</td><td>Integration Specialist</td><td>New York</td><td class=\"dt-body-right\">61</td><td class=\"dt-body-right\">12/1/2012</td><td class=\"dt-body-right dtr-hidden\" style=\"display: none;\">$372,000</td></tr><tr class=\"odd\"><td class=\"sorting_1 dtr-control\" tabindex=\"0\">Bruno Nash</td><td>Software Engineer</td><td>London</td><td class=\"dt-body-right\">38</td><td class=\"dt-body-right\">5/2/2011</td><td class=\"dt-body-right dtr-hidden\" style=\"display: none;\">$163,500</td></tr><tr class=\"even\"><td class=\"sorting_1 dtr-control\" tabindex=\"0\">Caesar Vance</td><td>Pre-Sales Support</td><td>New York</td><td class=\"dt-body-right\">21</td><td class=\"dt-body-right\">12/11/2011</td><td class=\"dt-body-right dtr-hidden\" style=\"display: none;\">$106,450</td></tr><tr class=\"odd\"><td class=\"sorting_1 dtr-control\" tabindex=\"0\">Cara Stevens</td><td>Sales Assistant</td><td>New York</td><td class=\"dt-body-right\">46</td><td class=\"dt-body-right\">12/5/2011</td><td class=\"dt-body-right dtr-hidden\" style=\"display: none;\">$145,600</td></tr><tr class=\"even\"><td class=\"dtr-control sorting_1\" tabindex=\"0\">Cedric Kelly</td><td>Senior Javascript Developer</td><td>Edinburgh</td><td class=\"dt-body-right\">22</td><td class=\"dt-body-right\">3/28/2012</td><td class=\"dt-body-right dtr-hidden\" style=\"display: none;\">$433,060</td></tr></tbody><tfoot><tr><th rowspan=\"1\" colspan=\"1\">Name</th><th rowspan=\"1\" colspan=\"1\">Position</th><th rowspan=\"1\" colspan=\"1\">Office</th><th class=\"dt-body-right\" rowspan=\"1\" colspan=\"1\">Age</th><th class=\"dt-body-right\" rowspan=\"1\" colspan=\"1\">Start date</th><th class=\"dt-body-right dtr-hidden\" rowspan=\"1\" colspan=\"1\" style=\"display: none;\">Salary</th></tr></tfoot></table>" --removehtml tableValues=first
// Only the previous table schema is copied
copyTable --schemaonly --dataTable ${tableValues} newTable=value
filterTable --where "Age>45" --dataTable ${tableValues} filterTable=value
for --variable ${row} --from 1 --to ${filterTable.Rows} --step 1
mapTableRow --dataTable ${filterTable} --row ${row} --mappings "number=1=${name},number=2=${position},number=3=${office},number=4=${age},number=5=${startDate}"
addRow --valuesmapping "Name=${name},Position=${position},Office=${office},Age=${age},Start date=${startDate}" --dataTable ${newTable}
next
// The values from the first and second table are displayed in the IBM RPA Studio console.
logMessage --message "\r\nFirst table:\r\n${tableValues}\r\n\r\nSecond table:\r\n${newTable}" --type "Info"