Workflow - changing Product Details section

Workflow - changing Product Details section

I decided to post my solution to this problem. Many forum posts suggests that Product Details section is uneditable, there is lots of misinformation in these posts as well as example 2 in documentation which suggest solution that doesn't work(link https://www.zoho.com/creator/help/script/crm-v2-update-records.html).

salesRec = zoho.crm.getRecordById("Sales_Orders",salesID);
productsList = salesRec.getJSON("Product_Details").toJSONList();
for each  product in productsList
{
     //Here you have to create some variables in order to later include them in complex map
    productID = product.getJSON("product").get("id");
    quantity = product.getJSON("quantity").toLong();
    discount = product.getJSON("Discount").toLong();
    totalAfterDiscount = product.getJSON("total_after_discount").toLong();
    netTotal = product.getJSON("net_total").toLong();
    book = product.getJSON("book");
    tax = product.getJSON("Tax").toLong();
    unitPrice = product.getJSON("unit_price");
    quantityInStock = product.getJSON("quantity_in_stock").toLong();
    productDespcription = product.getJSON("product_description");
    lineTax = product.getJSON("line_tax");
    productMap = zoho.crm.getRecordById("Products",productID);
    updatedProductMap = Map();
    productPrice = 0;
    if(currency == "EUR")
    {
        productPrice = productMap.get("Unit_Price_EUR");
    }
    else if(currency == "HRK")
    {
        productPrice = productMap.get("Unit_Price_HRK");
    }
    else if(currency == "PLN")
    {
        productPrice = productMap.get("Unit_Price_PLN");
    }
    else if(currency == "RSD")
    {
        productPrice = productMap.get("Unit_Price_RSD");
    }
    if(productPrice == null || productPrice == 0)
    {
        productPrice = 0;
    }
    else
    {
        productPrice = productPrice.toLong();
    }
    totalPrice = productPrice * quantity;
      //Here you have to copy map that you can find in response log under "Product_Details" api name
    JSONarray = {{"product":{"id":productID.toString()},"quantity":quantity,"Discount":discount,"total_after_discount":totalAfterDiscount,"net_total":netTotal,"book":book,"Tax":tax,"list_price":productPrice,"unit_price":unitPrice,"quantity_in_stock":quantityInStock,"total":productPrice,"product_description":productDespcription,"line_tax":lineTax}};
    updatedProductMap.put("Product_Details",JSONarray);
    rec = zoho.crm.updateRecord("Sales_Orders",salesRec.get("id"),updatedProductMap);
}

I hope I helped you in this simple matter.