Please note I'm not a deluge expert, but I have attempted to tweak a custom function but seem to be having issues with the last operation.
Essential the function should do the following:
- Get the Quote Details
- Iterate through the Quote Product Details line items
- Based on the Products in the Quote Product Details, it then creates Purchase Orders and attaches it to the Quote
Everything seems to work fine except for the last (and most important part) which is the actual creation of the Purchase Orders. The error message which is displaying is
"{"code":"INVALID_DATA","details":{"expected_data_type":"jsonarray","api_name":"Product_Details"},"message":"invalid data","status":"error"}"
Here is the code (the relevant parts)
---- Start -----
Get the Quote Details via an API Connection and create Map to use for Purchase Orders
quote_data_resp = invokeurl
[
type :GET
connection:"zcrm_connection"
];
data_mp = Map();
if(quote_data_resp.get("Contact_Name") == null || quote_data_resp.get("Contact_Name") == "")
{
}
else
{
data_mp.put("Contact_Name",quote_data_resp.get("Contact_Name").get("id"));
}
data_mp.put("Description",ifnull(quote_data_resp.get("Description"),""));
data_mp.put("Discount",quote_data_resp.get("Discount"));
data_mp.put("Tax",quote_data_resp.get("Tax"));
data_mp.put("PO_Date",po_date);
data_mp.put("Service_Details_Text_Version",ifnull(quote_data_resp.get("Additional_services_provided"),""));
data_mp.put("Solution",quote_id);
data_mp.put("Status","Created");
data_mp.put("Subject",ifnull(quote_data_resp.get("Subject"),""));
data_mp.put("Terms_and_Conditions",ifnull(quote_data_resp.get("Terms_and_Conditions"),""));
data_mp.put("PO_Number",quote_data_resp.get("Quote_No"));
soinfo = quote_data_resp.get("data").get(0);
product_list = soinfo.get("Quoted_Items");
Get the Product and associated Vendor from the Product Details of the Quote record
for each line_item in product_list
{
old_item = List();
po_item_li = List();
product_data = line_item.get("Product_Name");
info product_data;
item_id = product_data.get("id");
item_detail = zoho.crm.getRecordById("Products",item_id);
item_vendor = item_detail.get("Vendor_Name");
item_vendor_id = item_vendor.get("id");
search_po = zoho.crm.searchRecords("Purchase_Orders","(PO_Number:equals:" + quote_no + ")");
search_po_ids = List();
Get the Vendor Information
for each se_po in search_po
{
po_vendor = se_po.get("Vendor_Name");
po_vendor_id = po_vendor.get("id");
if(po_vendor_id == item_vendor_id)
{
se_po_id = se_po.get("id");
search_po_ids.add(se_po_id);
}
}
Create Purchase Orders from Maps
{
product_mp = Map();
item_mp = Map();
product_mp.put("Product_Code",ifnull(item_detail.get("Product_Code"),""));
product_mp.put("name",ifnull(item_detail.get("name"),""));
product_mp.put("id",ifnull(item_detail.get("id"),""));
//info product_mp;
item_mp.put("Product_Name",product_mp);
item_mp.put("quantity",line_item.get("quantity"));
item_mp.put("Discount",line_item.get("Discount"));
item_mp.put("Tax",line_item.get("Tax"));
item_mp.put("list_price",line_item.get("list_price"));
item_mp.put("product_description",line_item.get("product_description"));
//info item_mp;
po_item_li.add(item_mp);
//info po_item_li;
data_mp.put("Vendor_Name",item_vendor_id);
data_mp.put("Purchase_Items",po_item_li);
data_mp.put("Product_Details",product_mp);
info data_mp;
create_resp = zoho.crm.createRecord("Purchase_Orders",data_mp);
info create_resp;
}
}
return "Gigs have been created!";
---- end -----
This is the console error message:
Appreciate anyone who could help. I'm not a programmer, I'm an IT Administrator so this is out of my depth.
I have also attached a full copy of the code as a PNG file.