Unable to convert datatable using generative classifier

hi,
i have one invoice pdf file . i used generative classifier .after that Extract document data. the output is idocument data .
i can write the data in text file. but unable to convert this data into datable.



error like below

how to resolve this ?

i have attached invoice file.

Hi @anand_kumar4

The issue is that Extract Document Data is returning an ExtractedField(Of String), but you are trying to save it directly into a String.

You can fix it easily like this:

1. Create String variables

  • invoiceNumber
  • invoiceDate
  • purchaseOrder
  • shippingAddress
  • invoiceAmount

2. Use Assign activities

For example:

invoiceNumber = extract_Data.Data.InvoiceNumber.Value.ToString

Similarly:

invoiceDate = extract_Data.Data.InvoiceDate.Value.ToString

purchaseOrder = extract_Data.Data.PurchaseOrder.Value.ToString

shippingAddress = extract_Data.Data.ShippingAddress.Value.ToString

invoiceAmount = extract_Data.Data.InvoiceAmount.Value.ToString

3. Create a DataTable

Create dt_Invoice with columns:

InvoiceNumber | InvoiceDate | PurchaseOrder | ShippingAddress | InvoiceAmount

4. Use Add Data Row

In ArrayRow, use:

{invoiceNumber, invoiceDate, purchaseOrder, shippingAddress, invoiceAmount}

And select dt_Invoice as the DataTable.

That’s it. The important point is to use .Value because ExtractedField(Of String) is not directly compatible with a String variable.

For the line-item table in the invoice, you will need to loop through the extracted table data separately and add each item as a DataRow.

its working fine but table data coming in on line like below

how to resolve this ?

Hi @anand_kumar4

Since the invoice line items are extracted as a table, I would recommend not converting the complete DocumentData object directly to a DataTable.

For the line-item field, access the table value from the extracted field and iterate through each extracted row. Then create a DataTable with the required columns and add each row separately using Add Data Row.

Also, make sure you are not using .ToString() on the table value, as that will combine the complete table into a single string/cell.

If possible, please share the field name/schema of the line-item table from the extracted DocumentData; then we can provide the exact expression for accessing the rows.

Hi @anand_kumar4 ,
ExtractedField(Of String()) ≠ String. Extract the .Value / individual value first instead of assigning the complete extracted field.

Thanks

Hi @anand_kumar4,

I see you are able to get data correctly until “InvoiceAmount” column. But you are getting line items data as a string into the “Quantity” column.

You can use For Each Row in DataTable activity and get that Quantity column value into a variable and then pass it to this workflow. This will create a new DataTable from which you can easily extract the data.
GetTableItemsData.xaml (14.5 KB)

Cheers!

@anand_kumar4 Hi @anand_kumar4,

Your scalar fields such as InvoiceNumber, InvoiceDate, PurchaseOrder, ShippingAddress and InvoiceAmount are now working correctly.

The remaining issue is with the line-item table. Currently the complete extracted table is being converted/added as one value, which is why all Quantity, Item No., Description, Unit Price, Amount, etc. are appearing in a single cell.

Do not use .ToString() for the extracted table field.

Handle the line-item table separately:

  1. Get the extracted table field from extract_Data.
  2. Access its table/rows collection.
  3. Loop through each extracted row.
  4. Create a separate DataTable with columns such as:
    Quantity | ItemNo | Description | UnitPrice | Amount
  5. Inside the loop, use Add Data Row to add one row for each invoice item.

Your invoice header DataTable and line-item DataTable should ideally be separate because one invoice contains one set of header values but multiple line-item rows.

For example:

dt_InvoiceHeader

InvoiceNumber | InvoiceDate | PurchaseOrder | ShippingAddress | InvoiceAmount

and

dt_LineItems

Quantity | ItemNo | Description | UnitPrice | Amount

If you share the exact table field name and its datatype/available properties from extract_Data.Data, we can provide the exact UiPath expression for iterating through the rows.