String id = context.data._id as String
String account_id = context.data.account_id == null ? "" : context.data.account_id as String
String amount_company = context.data.amount_company__c as String
log.info(id)
log.info(account_id)
//log.info(context.data)
if (account_id != "") {
def (Boolean error, Map data, String errorMessage) = Fx.object.findById(
"AccountObj",
account_id,
FQLAttribute.builder()
.columns(["_id", "name", "customer_name__c"])
.build(),
SelectAttribute.builder()
.build()
);
if (error) {
log.info(errorMessage);
}
log.info(data)
// 定义变量并赋值
String name = data.name as String
String nameStr = data.customer_name__c == null ? "" : data.customer_name__c as String
List<String> nameList = []
// 添加名称到列表
nameList.add(name)
// 如果名称不包打款公司,则添加到列表
if (!name.contains(amount_company)) {
nameList.add(amount_company)
}
// 如果 nameStr 不为空,则处理并添加到列表
if (nameStr) {
// 检查 nameStr 是否包含分隔符 "/"
if (nameStr.contains("/")) {
List<String> nameStrList = nameStr.split("/").toList()
nameStrList.each { customerName ->
if (!name.contains(customerName)) {
nameList.add(customerName)
}
}
} else {
if (!name.contains(nameStr)) {
nameList.add(nameStr)
}
}
}
// 去重并打印
nameList = nameList.unique()
log.info(nameList)
// 将列表拼接成字符串
String nameNewStr = nameList.join("/")
log.info(nameNewStr)
//相关客户名称
def objectMap = ["customer_name__c": nameNewStr]
def result = Fx.object.update("AccountObj", account_id, objectMap, null, ActionAttribute.create()).result() as Map
log.info(result)
if (result) {
//CRM-TO-YS:更新YS客户名称
def (Boolean errorKh, HttpResult resultKh, String errorMessageKh) = Fx.http.get("http://ys.test.com/crmToYs?xkId=" + account_id)
if (errorKh || resultKh.statusCode != 200) {
log.info("error :" + errorMessageKh)
} else {
log.info(resultKh)
}
}
} else {
log.info("未找到关联客户")
}
参考:
1、Fx.object.findById
Fx.object | 纷享销客 | 帮助中心
2、Fx.object.update
Fx.object | 纷享销客 | 帮助中心
3、Fx.http.get
Fx.http | 纷享销客 | 帮助中心