SugarCRM - 使用自动递增的ID添加潜在客户

时间:2012-08-14 14:01:43

标签: api soap sugarcrm

我使用SOAP API向SugarCRM添加新的潜在客户。此外,每当创建新的潜在客户时,我都会使用插件分配自动递增的潜在客户ID(http://www.sugarforge.org/projects/autoincrement/)。

现在,如果我通过前端创建一个新的引导,插件工作正常。但是,如果我使用SOAP API,则模块中的函数(它将自动增量ID分配给引导程序)不会触发。

我通过

创建了潜在客户
    $module = 'Leads'; 

    $params = array(
        'session'           =>  $session,
        'module_name'       =>  $module,
        'name_value_list'   =>  array(
            array('name' => 'id',               'value' => ''),
            //array('name' => 'int_lead_id_c',  'value' => ''),             
            array('name' => 'first_name',       'value' => $_POST["first_name"]),
            array('name' => 'last_name',        'value' => $_POST["last_name"]),
            array('name' => 'phone_home',       'value' => $_POST["phone"]),
            array('name' => 'email1',           'value' => $_POST["email"]),
            array('name' => 'assigned_user_id', 'value' => '1'),
            )
        );  

    //Create the Lead record
    $lead_result = $soapclient->call('set_entry', $params);

模块中的功能就是这个:

class SugarFieldAutoincrement extends SugarFieldBase {

    /**
     * Override the SugarFieldBase::save() function to implement the logic to get the next autoincrement value
     * and format the saved value based on the attributes defined for the field.
     *
     * @param SugarBean bean - the bean performing the save
     * @param array params - an array of paramester relevant to the save, most likely will be $_REQUEST
     * @param string field - the name of the field
     */
    public function save(&$bean, $params, $field, $properties, $prefix = '') {
    }
}

在通过SOAP API添加潜在客户时,如何确保此功能也被触发?

非常感谢你的帮助! : - )

大卫

3 个答案:

答案 0 :(得分:1)

您需要在字段的vardef记录中将字段类型设置为“autoincrement”并将dbType设置为“int”。

答案 1 :(得分:0)

如果我没有弄错,数据库在大多数表的插入上都有一个UUID()触发器,因此你应该能够完全删除id字段。

答案 2 :(得分:0)

如果要在保存之前触发该功能,可以使用beforeSave逻辑钩子。