Custom Function To Fetch Product Custom Field From Invoice Product Details Subform

Custom Function To Fetch Product Custom Field From Invoice Product Details Subform

Hello,

I am trying to fetch a custom field from a product and bring it into the corresponding line item in the Product Details subform of an invoice.

The product field which I am after has the API name Set_cost while the custom field in the Product Details subform is Net_Cost. I have looked across various posts on this forum and while many requirements are similar they mostly seem to involve adding a line to the invoice rather than updating a field in an existing one.

The current code which I am working from is below, though there have been many prior iterations and none have worked. Please can you advise?

  1. recordDetails = zoho.crm.getRecordById("Invoices", IoId);
  2. subformEntries = recordDetails.get("Product_Details");
  3. productList = subformEntries.toJSONList();

  4. statusList = list();
  5. for each entry in subformEntries
  6. {
  7. pSetCost = entry.get("product").get("Set_Cost");
  8. statusList.add(pSetCost);
  9. }

  10. mp = map();
  11. mp.put("Net_Cost", pSetCost);
  12. updateMainRecord = zoho.crm.updateRecord("Invoices",IoId, {"Product_Details" : mp});
  13. info updateMainRecord;

Many thanks