在自定义函数中使用 Zoho Deluge 脚本解决问题

问题描述

对于 1200 多个帐户,我需要如下输出

accounts_count = {
    "a": 120,"b": 45,"z": 220
}

因此它将取帐户名称的第一个字母,并以其首字母计算所有帐户。

如何在自定义函数中使用 Zoho Deluge 脚本解决该问题?

解决方法

由于 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;
}