I tried the following code but it failed when it tried to convert the custom field list to a list.
lineItems = invoice.get("line_items").toList();
for each item in lineItems
{
item_CFs = item.get("custom_fields").toList();
for each item_cf in item_CFs
{
msg = msg + item_cf.get("value").toString();
}
}