背景和背景
我正在尝试在 SugarCRM 8.0 中创建一个自定义 REST 模块,该模块在链接字段上连接两个模块。这两个模块是;
- 帐户(OOTB 模块)
- ConsumerLeads(自定义模块)
这两个模块是一个名为w002_consumerleads_accounts_1的链接字段,因此当我调用以下端点时,我会收到一个 JSON 响应,其中包含与该特定帐户 uuid 关联的所有 ConsumerLead 数据。
/rest/v11_4/Accounts/{ account_uuid }/link/w002_consumerleads_accounts_1
但是,我的自定义模块不是基于帐户 uuid 返回连接结果,而是基于唯一标识帐户的不同帐户属性返回连接结果。
/rest/v11_4/customer/{ customer_id }/leads
我试图为此构建一个自定义模块(而不是使用上面列出的预定义的 rest api)的原因是由于调用此调用的系统不知道糖帐户 uuid,而是知道唯一的业务密钥标识帐户(并且是帐户模块上的一个属性)。
问题
当我在自定义休息模块中使用 SugarQuery 来加入 Accounts 和 ConsumerLeads 时,我的结果与第一个休息 api(预定义的休息 api)中指定的结果不匹配。结果只返回Accounts模块,不加入ConsumerLeads模块。
问题在于链接字段上的两个模块的连接;该问题与使用客户 uuid v. 帐户 uuid 无关。
参考实现
根据 SugarCRM 开发人员指南,我编写了以下代码。
public function GetLinkLeads($api, $args) {
try {
$query = new SugarQuery();
$query->from(BeanFactory::getBean('Accounts'));
$query->join('w002_consumerleads_accounts_1');
$query->limit(10);
$results = $query->execute();
return $results;
} catch ( Exception $e ) {
return $e->getCode();
}
return 1;
}
根据我能收集到的所有信息,此函数应返回与其 ConsumerLeads 连接的前 10 个帐户记录。但是,响应只包含 Accounts 模块数据,它不加入 ConsumerLeads 数据。
此外,我还尝试了以下方式。
public function GetLinkLeads($api, $args) {
try {
$account = BeanFactory::getBean('Accounts', '4606e963-9213-7764-d83f-4cc050c8473d');
if ( $account->load_relationship('w002_consumerleads_accounts_1') ) {
$lead = $account->w002_consumerleads_accounts_1->getBeans();
return $lead;
}
} catch ( Exception $e ) {
return $e->getCode();
}
return 1;
}
与 ConsumerLeads 关联的帐户 uuid在哪里4606e963-9213-7764-d83f-4cc050c8473d
,但我仍然无法让 ConsumerLeads 数据返回。
问题
我想:
- 使用 SugarQuery() 基于链接字段连接这两个模块
- 使用默认的rest api基于Accounts模块上的一个属性加入两个模块(不是账户uuid)
我在 Stack Overflow 上找到了这个确切的问题,上面的实现是基于该帖子的建议。但是,它仍然没有加入记录。