You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Deluge解决Zoho CRM嵌套数组子表单计算字段更新失败问题

解决Zoho CRM Quotes子表单字段更新失败问题

我在Zoho CRM的Quotes模块中,Quoted_Items子表单包含quantity、standard_price和extended_standard_price三个字段,需要计算quantity与standard_price的乘积,将结果更新到extended_standard_price字段。目前代码能成功获取数据,但无法完成更新操作,原代码如下:

fetch_record = invokeurl
[
url :"https://www.zohoapis.in/crm/v6/Quotes/683769000000338181"
type :GET
connection:"fetch_data_1"
];
//info fetch_record;
information = fetch_record.get("data");
for each  rec in information
{
quoted_items = rec.get("Quoted_Items");
main_map = Map();
extended_standard_prices = List();
// Accessing each quoted item
for each  item in quoted_items
{
    //maps = Map();
    //maps.put("extended_standard_price",item);
    quantity = item.get("Quantity");
    //info quantity;
    standard_price = item.get("Standard_Price");
    //info standard_price;
    extended_standard_price = quantity * standard_price;
    extended_standard_prices.add(extended_standard_price);
   
}
info extended_standard_prices;
main_map.put("Quoted_Items",extended_standard_prices);
info main_map;
update_resp1 = zoho.crm.updateRecord("Quotes",formula_id,main_map);
info update_resp1;

}

问题分析

原代码的核心问题是子表单更新的格式错误:

  • Zoho CRM更新子表单时,需要传递包含每个子条目id和目标字段的Map列表,而非单纯的数值列表
  • 未携带子条目的id,系统无法识别要更新哪个子表单条目
  • 仅传递计算后的数值,没有关联对应的字段键名,系统无法匹配到目标字段

修正后的代码

fetch_record = invokeurl
[
url :"https://www.zohoapis.in/crm/v6/Quotes/683769000000338181"
type :GET
connection:"fetch_data_1"
];

information = fetch_record.get("data");
for each rec in information
{
    quoted_items = rec.get("Quoted_Items");
    main_map = Map();
    updated_quoted_items = List();
    
    // 遍历每个子表单条目,构造更新所需的Map
    for each item in quoted_items
    {
        item_map = Map();
        // 获取子条目ID,这是更新的关键标识
        item_id = item.get("id");
        quantity = item.get("Quantity");
        standard_price = item.get("Standard_Price");
        extended_standard_price = quantity * standard_price;
        
        // 组装子条目更新数据:必须包含id和目标字段
        item_map.put("id", item_id);
        item_map.put("extended_standard_price", extended_standard_price);
        
        updated_quoted_items.add(item_map);
    }
    
    // 组装主更新Map,符合Zoho CRM的子表单更新格式
    main_map.put("Quoted_Items", updated_quoted_items);
    
    // 替换为当前Quote记录的ID,避免变量名混淆
    update_resp1 = zoho.crm.updateRecord("Quotes", rec.get("id"), main_map);
    info update_resp1;
}

关键修正点说明

  1. 保留子条目ID:每个Quoted_Items子条目都有唯一的id,更新时必须携带该ID,否则系统无法定位要修改的条目
  2. 构造子条目Map:每个子条目需用Map存储,包含id和extended_standard_price的键值对,明确指定要更新的字段和对应值
  3. 修正记录ID变量:直接从获取的主记录中取rec.get("id")作为更新的目标Quote ID,避免变量名错误
  4. 正确组装更新结构:主Map中的Quoted_Items对应的值是子条目Map的列表,而非单纯的数值列表,完全匹配Zoho CRM API的更新格式要求

内容的提问来源于stack exchange,提问作者Mudassar Saiyed

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 06:55:20