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

Deluge函数语法错误排查:通过邮编更新Zoho CRM地址字段

Zoho Deluge函数:通过邮编调用Google Geocoding API填充地址(语法错误修复)

问题描述

编写的联系人创建时自动触发的Deluge函数,意图通过邮编调用Google Geocoding API获取完整地址并更新到Zoho CRM的Address字段,但保存函数时失败,报错信息:

保存函数失败,语法错误。第11行发现'[',预期为executeshellscript任务、表达式、invokeurl任务或'invokeintegration'。

原代码如下:

leadDetails = zoho.crm.getRecordById("ARCH_Concept_Ltd",input.leadId);

// Make API call to Google Maps Geocoding API
api_key = "API_Number";
postcode = ifnull(leadDetails.get("Postcode"),"");
api_url = "https://maps.googleapis.com/maps/api/geocode/json?address="+postcode+"&key="+api_key;
response = http.get(api_url.toURL());

// Parse the response to extract the street address
data = json.parse(response.getContent());
address = data.results[0].formatted_address;

// Store the address in the "Address" field
mp = Map();
mp.put("Address",address);
update = zoho.crm.updateRecord("ARCH_Concept_Ltd",leadId.toLong(),mp);
info mp;
info update;

错误原因

Deluge语言不支持常规编程语言中用方括号[索引]直接访问数组元素的语法,第11行的data.results[0]不符合Deluge的规则,需改用Deluge专属的数组访问方法。

修复后的代码

leadDetails = zoho.crm.getRecordById("ARCH_Concept_Ltd", input.leadId);

// 调用Google Maps Geocoding API
api_key = "你的Google API密钥";
postcode = ifnull(leadDetails.get("Postcode"), "");
api_url = "https://maps.googleapis.com/maps/api/geocode/json?address=" + postcode + "&key=" + api_key;
response = http.get(api_url.toURL());

// 解析响应并提取地址
data = json.parse(response.getContent());
results = data.get("results");
if (results.size() > 0) {
    firstResult = results.get(0);
    address = firstResult.get("formatted_address");
    
    // 更新Address字段
    mp = Map();
    mp.put("Address", address);
    update = zoho.crm.updateRecord("ARCH_Concept_Ltd", input.leadId.toLong(), mp);
    info mp;
    info update;
}
else {
    info "未找到该邮编对应的地址信息";
}

关键修改点

  • 用data.get("results")获取结果数组,替代原代码的data.results
  • 用results.get(0)获取数组第一个元素,替代data.results[0]
  • 添加数组非空判断,避免因API返回无结果导致的后续错误
  • 修正leadId.toLong()为input.leadId.toLong(),确保变量来源正确

注意事项

  • 替换"你的Google API密钥"为实际有效的Google Geocoding API密钥
  • 确保Zoho CRM模块名称"ARCH_Concept_Ltd"、字段名"Postcode"和"Address"与模块内配置一致
  • 需为Deluge函数配置正确的触发条件(联系人创建时触发)

内容的提问来源于stack exchange,提问作者D M

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.04 04:20:24