gpt4 book ai didi

php - 在 SugarCRM 自定义字段中添加值的 Hook

转载 作者:行者123 更新时间:2023-12-04 05:09:18 24 4
gpt4 key购买 nike

我是 SugarCRM 的新手。我在 session 模块中创建了一个名为“帐户名称”的自定义字段,因此如果我们从相关字段中选择联系人,该联系人的“帐户名称”会自动添加到该字段中。

这是我的代码:

$hook_array['after_retrieve'] = Array(); 
$hook_array['after_retrieve'][] = Array(1, 'Add custom account',
'custom/modules/Meetings/AddAccount.php','AddAccount', 'addAcc');

逻辑 Hook :
class AddAccount
{
public function addAcc(&$bean, $event, $arguments)
{
global $current_user;
global $db;

echo "<pre>";
$meeting_id = $_REQUEST['record'];
$query = "SELECT * FROM `meetings_contacts` WHERE `meeting_id` LIKE '$meeting_id'";
$result = $bean->db->query($query, true, " Error filling in additional detail fields: ");

if ($bean->db->getRowCount($result) > 0) {
while ($row = $bean->db->fetchByAssoc($result)) {
$contact_id = $row['contact_id'];
}
if (isset($contact_id)) {
$query1 = "SELECT * FROM `accounts_contacts` WHERE `contact_id` LIKE '$contact_id'";
$result1 = $bean->db->query($query1, true, " Error filling in additional detail fields: ");

while ($row1 = $bean->db->fetchByAssoc($result1)) {
$account_id = $row1['account_id'];
}

$query2 = "SELECT * FROM `accounts` WHERE `id` LIKE '$account_id'";
$result2 = $bean->db->query($query2, true, " Error filling in additional detail fields: ");

while ($row2 = $bean->db->fetchByAssoc($result2)) {
$account_name = $row2['name'];
}

$update_custom_account = "UPDATE `meetings_cstm` SET `accountname_c` = '$account_name' WHERE `meetings_cstm`.`id_c` = '$meeting_id';";
$Change = $bean->db->query($update_custom_account);
}
}
}
}

问题是该字段正在添加,但 ListView 中的“i”已停止工作。有没有比这个长查询更简单的方法?

提前致谢。

最佳答案

这是执行上述操作的更好方法。
自定义/模块/ session /logic_hooks.php

// position, file, function
$hook_array['after_retrieve'] = Array();
$hook_array['after_retrieve'][] = Array(1, 'Add custom account', 'custom/modules/Meetings/AddAccount.php', 'AddAccount', 'getAccountName');
$hook_array['after_save'] = Array();
$hook_array['after_save'][] = Array(1, 'Add custom account', 'custom/modules/Meetings/AddAccount.php', 'AddAccount', 'getAccountName');
自定义/模块/ session /AddAccount.php
class AddAccount {

public function getAccountName(&$bean, $event, $arguments) {

if ($bean->parent_type == 'Contacts') {
$contact = BeanFactory::getBean('Contacts', $bean->parent_id);
$contact->load_relationship('accounts_contacts');

$account = BeanFactory::getBean('Accounts', $contact->account_id);
$bean->account_name_c = $account->name;
}
}
}
这样,您使用的是 bean 而不是 SQL。
编辑:
要添加新字段,您可以创建此文件...
自定义/扩展/模块/ session /Ext/Vardefs/account_name_c.php
<?php
$dictionary['Meeting']['fields']['account_name_c'] =
array (
'name' => 'account_name_c',
'vname' => 'LBL_ACCOUNT_NAME_C',
'type' => 'varchar',
'len' => '255',
'unified_search' => true,
'comment' => 'Account name for meeting',
'studio' => 'true',
);
然后在修复/重建后,转到 Studio > Meetings > Layouts > ListView 并将新字段从“隐藏”拖放到“默认”。选择“保存并部署”按钮,保存 session 记录后,您的帐户名称将出现在 ListView 中。

关于php - 在 SugarCRM 自定义字段中添加值的 Hook ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15081906/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com