【发布时间】:2021-10-02 02:42:15
【问题描述】:
对于 1200 多个帐户,我需要如下输出:
accounts_count = {
"a": 120,
"b": 45,
"z": 220
}
因此它将采用帐户名称的第一个字母,并计算所有帐户的首字母。
如何在自定义函数中使用 Zoho Deluge 脚本解决此问题?
【问题讨论】:
标签: zoho
对于 1200 多个帐户,我需要如下输出:
accounts_count = {
"a": 120,
"b": 45,
"z": 220
}
因此它将采用帐户名称的第一个字母,并计算所有帐户的首字母。
如何在自定义函数中使用 Zoho Deluge 脚本解决此问题?
【问题讨论】:
标签: zoho
由于 zoho 中的 200 条记录限制,困难的部分是获取所有联系人
我不会在这里提供完整的解决方案,只提供更难的部分。
// this is the maximum number of records that you can query at once
max = 200;
// set to a value slightly higher than you need
max_contacts = 1500;
// round up one
n = max_contacts / max + 1;
// This is how many times you will loop (convert to int)
iterations = n.toNumber();
// this is a zoho hack to create a range of the length we want
counter = leftpad("1",iterations).replaceAll(" ","1,").toList();
// set paging
page = 1;
// TODO: initialize an alphabet map
//result = Map( {a: 0, b:0....});
// set to true when done so you're not wasting API Calls
done = false;
for each i in counter
{
// prevent extra crm calls
if(!done)
{
response = zoho.crm.getRecords("Contacts",page,max);
if(!isEmpty(response))
{
if(isNull(response.get(0)) && !isNull(response.get("code")))
{
info "Error:";
info response;
}
else
{
for each user in response
{
// this is the easy part: get the first letter (lowercase)
// get the current value and add one
// set the value again
// set in result map
}
}
}
else
{
done = true;
}
}
// increment the page
page = page + 1;
}
【讨论】: