自动化函数里调用另一个函数的样例

自动化函数里调用另一个函数的样例

使用场景:某个用户字段更新后,需要将相关列表数据共享给用户字段本人和上级。由于很多模块都有相同的需求,所以可以将“共享给用户字段和上级”封装到一个独立的函数中,每个模块在调用的时候传参即可。

样例函数:

1、单机版函数

//获取业务员信息
searchList = zoho.crm.getRecordById("users",yeWuYuanId);
info searchList;
if(searchList.size() > 0)
{
//获取业务员
yeWuYuan = searchList.get("users").get(0);
//获取业务员的报告上级
reportingTo = yeWuYuan.get("Reporting_To");
info "报告上级:" + reportingTo;
if(reportingTo.isNull())
{
//共享给业务员
user1 = Map();
user1.put("shared_with",{"id":"" + yeWuYuanId + "","type":"users"});
user1.put("permission",permission);
user1.put("share_related_records",true);
user1.put("type","private");
info user1;
userList = List();
userList.add(user1);
param = Map();
param.put("share",userList);
}
else
{
userList = List();
//共享给业务员和业务员的上级
user1 = Map();
user1.put("shared_with",{"id":"" + yeWuYuanId + "","type":"users"});
user1.put("permission",permission);
user1.put("share_related_records",true);
user1.put("type","private");
userList.add(user1);
user2 = Map();
user2.put("shared_with",{"id":"" + reportingTo.get("id") + "","type":"users"});
user2.put("permission",permission);
user2.put("share_related_records",true);
user2.put("type","private");
userList.add(user2);
//查找上两级
twoLevelsDetail = zoho.crm.getRecordById("users",reportingTo.get("id"));
info "上两级用户详情:" + twoLevelsDetail;
twoLevels = twoLevelsDetail.get("users").get(0).get("Reporting_To");
info "上两级:" + twoLevels;
if(!twoLevels.isNull())
{
user3 = Map();
user3.put("shared_with",{"id":"" + twoLevels.get("id") + "","type":"users"});
user3.put("permission",permission);
user3.put("share_related_records",true);
user3.put("type","private");
userList.add(user3);
//查找上三级
threeLevelsDetail = zoho.crm.getRecordById("users",twoLevels.get("id"));
threeLevels = threeLevelsDetail.get("users").get(0).get("Reporting_To");
info "上三级:" + threeLevels;
if(!threeLevels.isNull())
{
user4 = Map();
user4.put("shared_with",{"id":"" + threeLevels.get("id") + "","type":"users"});
user4.put("permission",permission);
user4.put("share_related_records",true);
user4.put("type","private");
userList.add(user4);
//查找上四级
fourLevelsDetail = zoho.crm.getRecordById("users",threeLevels.get("id"));
fourLevels = fourLevelsDetail.get("users").get(0).get("Reporting_To");
info "上四级:" + fourLevels;
if(!fourLevels.isNull())
{
user5 = Map();
user5.put("shared_with",{"id":"" + fourLevels.get("id") + "","type":"users"});
user5.put("permission",permission);
user5.put("share_related_records",true);
user5.put("type","private");
userList.add(user5);
//查找上五级
fiveLevelsDetail = zoho.crm.getRecordById("users",fourLevels.get("id"));
fiveLevels = fiveLevelsDetail.get("users").get(0).get("Reporting_To");
info "上五级:" + fiveLevels;
if(!fiveLevels.isNull())
{
user6 = Map();
user6.put("shared_with",{"id":"" + fiveLevels.get("id") + "","type":"users"});
user6.put("permission",permission);
user6.put("share_related_records",true);
user6.put("type","private");
userList.add(user6);
}
}
}
}
param = Map();
param.put("share",userList);
}
info "json数据:" + param;
//调用接口
response = invokeurl
[
url :"https://www.zohoapis.com.cn/crm/v3/" + module + "/" + recordId + "/actions/share"
type :POST
parameters:param.toString()
connection:"crm"
];
info response;
//获取code
status = response.get("share").get(0).get("status");
if(status == "success")
{
return "共享成功!";
}
else
{
return "共享失败!";
}
}
else
{
return "找不到这个业务员!";
}

2、获取单机版函数的API链接



3、自动化函数

map = Map();
//模块API
map.put("module","CustomModule20");
//记录ID
map.put("id",id);
//跟单员的ID
map.put("merchandiser",respAccounts.get("field121").get("id"));
//分享的权限:
//full_access:允许用户完全访问记录
//read_only:允许用户仅查看记录--只读
//read_write:  允许用户查看和编辑记录--读写
map.put("permission","read_only");
info map;
//url里填写的是单机版函数的API链接
success = invokeurl
[
type :GET
parameters:map
];
info success;