Sales Order Line Items to Map() then list()

Sales Order Line Items to Map() then list()

I'm attempting to get the line items of a sales order dumped into a Map() and then the map of each line put into a list(). Or honestly a simpler option if possible this is just what I've come up with based on some of the working Deluge code that I've seen which transfers line items from a sales order into another type of module such as a purchase order. I just need that data extracted and then dumped either into Sheet or Creator. I've been trying to accomplish this for the past couple of days in Flow but figured that maybe I could do it right in Books. One of my coding attempts is below.


CSO_LineItems = "line_items" ;
itemsList = list();
LineItemRecords = CSO_LineItems.toList();
for each  LineItemRecord in LineItemRecords
{
itemEach = Map();
item = LineItemRecord.toMap();
itemEach.put("line_item_id",item.get("line_item_id"));
itemEach.put("sku",item.get("sku"));
itemEach.put("name",item.get("name"));
itemEach.put("case_pack",item.get("cf_case_pack"));
itemEach.put("bin_location",item.get("cf_bin_location"));
itemEach.put("quantity",item.get("quantity"));
itemEach.put("rate",item.get("rate"));
itemsList.add(itemEach);
}
response = zoho.sheet.insertCSV("g1rq59b27c52fb986431d8d0cbe8cf7c1a8de","Sheet1",itemsList,5,1);