使用SugarCRM 7 API过滤没有无效电子邮件和退订电子邮件的列表

时间:2017-03-08 09:41:15

标签: php rest sugarcrm

我想使用SugarCRM 7 API过滤Leads and Contact模块中没有无效电子邮件和退订电子邮件的列表。

我在参数中添加了以下电子邮件过滤器但不起作用。如何通过SugarCRM 7.x rest API发送电子邮件过滤器。

$filter_arguments = array(

            "filter" => array(

                array(
                    "assigned_user_id" => 1,
                ),
                array(
                    "email1" => array(
                        array(
                            'opt_out' => array(
                                '$equals' => ''
                            )
                        )
                    )
                ),
            ),
        );
$url = $base_url . "/Contacts/filter";

感谢。

1 个答案:

答案 0 :(得分:1)

这么多代码对你没有帮助,请查看:

Reference Link 1

Reference Link 2

以下示例将演示如何在“帐户”模块上添加预定义过滤器,以返回帐户类型为"客户" "其他"。

要创建预定义过滤器,请在./custom/Extension/modules/<module>/Ext/Language/中创建显示标签扩展名。对于此示例,我们将创建:

./custom/Extension/modules/Accounts/Ext/Language/en_us.filterAccountByTypeAndIndustry.php

<?php

$mod_strings['LBL_FILTER_ACCOUNT_BY_TYPE_AND_INDUSTRY'] = 'Customer/Other Accounts';

接下来,在./custom/Extension/modules/<module>/Ext/clients/base/filters/basic/.

中创建自定义过滤器扩展程序

对于此示例,我们将创建:

./custom/Extension/modules/Accounts/Ext/clients/base/filters/basic/filterAccountByTypeAndIndustry.php

<?php

$viewdefs['Accounts']['base']['filter']['basic']['filters'][] = array(
    'id' => 'filterAccountByTypeAndIndustry',
    'name' => 'LBL_FILTER_ACCOUNT_BY_TYPE_AND_INDUSTRY',
    'filter_definition' => array(
        array(
            'account_type' => array(
                '$in' => array(
                    'Customer',
                ),
            ),
        ),
        array(
            'industry' => array(
                '$in' => array(
                    'Other',
                ),
            ),
        ),
    ),
    'editable' => false,
    'is_template' => false,
);

您应该注意到editable和is_template选项已设置为&#34; false&#34;。如果editable未设置为&#34; false&#34;,则过滤器将不会显示在列表视图过滤器列表中。

最后,导航至管理员&gt;修复并点击&#34;快速修复和重建&#34;重建扩展并为用户提供预定义过滤器。 向查找搜索添加初始过滤器

要添加初始过滤器以记录查找和预先输入搜索,请定义过滤器模板。这将允许您在查找父相关记录时过滤用户的结果。以下示例将演示如何在“联系人”模块上为“帐户”查找添加初始过滤器。此初始过滤器会将记录限制为帐户类型为&#34;客户&#34;以及由联系人分配的用户确定的动态分配的用户值。

要在“联系人”记录视图中添加初始过滤器,请在./custom/Extension/modules/<module>/Ext/Language/. For this example , we will create:

中为过滤器创建显示标签
./custom/Extension/modules/Accounts/Ext/Language/en_us.filterAccountTemplate.php

<?php

$mod_strings['LBL_FILTER_ACCOUNT_TEMPLATE'] = 'Customer Accounts By A Dynamic User';

接下来,在./custom/Extension/modules/<module>/Ext/clients/base/filters/basic/中创建自定义模板过滤器扩展程序。  对于此示例,请创建:

./custom/Extension/modules/Accounts/Ext/clients/base/filters/basic/filterAccountTemplate.php

<?php

$viewdefs['Accounts']['base']['filter']['basic']['filters'][] = array(
    'id' => 'filterAccountTemplate',
    'name' => 'LBL_FILTER_ACCOUNT_TEMPLATE',
    'filter_definition' => array(
        array(
            'account_type' => array(
                '$in' => array(),
            ),
        ),
        array(
            'assigned_user_id' => ''
        )
    ),
    'editable' => true,
    'is_template' => true,
);

如您所见,filter_definition包含account_type和assigned_user_id的数组。这些过滤器定义将从联系人记录视图的元数据中接收其值。您还应注意,此过滤器的is_template和editable设置为&#34; true&#34;。这是初始过滤器所必需的。

过滤器模板到位后,修改联系人记录视图的元数据。要完成此操作,请编辑./custom/modules/Contacts/clients/base/views/record/record.php以调整account_name字段。如果您的本地Sugar安装中不存在此文件,请导航至Admin&gt;工作室&gt;联系人&gt;布局&gt;记录视图并单击&#34;保存&amp;部署&#34;生成它。在此文件中,标识panel_body数组,如下所示:

1 => 
array (
    'name' => 'panel_body',
    'label' => 'LBL_RECORD_BODY',
    'columns' => 2,
    'labelsOnTop' => true,
    'placeholders' => true,
    'newTab' => false,
    'panelDefault' => 'expanded',
    'fields' => 
    array (
        0 => 'title',
        1 => 'phone_mobile',
        2 => 'department',
        3 => 'do_not_call',
        4 => 'account_name',
        5 => 'email',
    ),
),

接下来,修改account_name字段以包含初始过滤器参数。

1 =>
array (
    'name' => 'panel_body',
    'label' => 'LBL_RECORD_BODY',
    'columns' => 2,
    'labelsOnTop' => true,
    'placeholders' => true,
    'newTab' => false,
    'panelDefault' => 'expanded',
    'fields' =>
    array (
        0 => 'title',
        1 => 'phone_mobile',
        2 => 'department',
        3 => 'do_not_call',
        4 => array (
            //field name
            'name' => 'account_name',

            //the name of the filter template
            'initial_filter' => 'filterAccountTemplate',

            //the display label for users
            'initial_filter_label' => 'LBL_FILTER_ACCOUNT_TEMPLATE',



     //the hardcoded filters to pass to the templates filter definition
            'filter_populate' => array(
                'account_type' => array('Customer')
            ),

            //the dynamic filters to pass to the templates filter definition
            //please note the index of the array will be for the field the data is being pulled from
            'filter_relate' => array(
                //'field_to_pull_data_from' => 'field_to_populate_data_to'
                'assigned_user_id' => 'assigned_user_id',
            )
        ),
        5 => 'email',
    ),
),

最后,导航至管理员&gt;修复并单击&#34;快速修复和重建&#34;。这将重建扩展,并在为联系人选择父帐户时为用户提供初始过滤器。 从控制器向抽屉添加初始过滤器

创建自己的视图时,可能需要过滤从自定义控制器中调用的抽屉。使用初始过滤器,如添加初始过滤器到查找搜索部分所述,我们可以通过创建过滤器对象并填充config.filter_populate属性来过滤具有预定义值的抽屉,如下所示:

//create filter
var filterOptions = new app.utils.FilterOptions()
    .config({
        'initial_filter': 'filterAccountTemplate',
        'initial_filter_label': 'LBL_FILTER_ACCOUNT_TEMPLATE',
        'filter_populate': {
            'account_type': ['Customer'],
            'assigned_user_id': 'seed_sally_id'
        }
    })
    .format();

//open drawer
app.drawer.open({
    layout: 'selection-list',
    context: {
        module: 'Accounts',
        filterOptions: filterOptions,
        parent: this.context
    }
});

要创建具有动态值的过滤器抽屉,请创建过滤器对象并使用populateRelate方法填充config.filter_relate属性,如下所示:

//record to filter related fields by
var contact = app.data.createBean('Contacts', {
    'first_name': 'John',
    'last_name': 'Smith',       
    'assigned_user_id': 'seed_sally_id'
});

//create filter
var filterOptions = new app.utils.FilterOptions()
    .config({
        'initial_filter': 'filterAccountTemplate',
        'initial_filter_label': 'LBL_FILTER_ACCOUNT_TEMPLATE',
        'filter_populate': {
            'account_type': ['Customer'],
        },
        'filter_relate': {
            'assigned_user_id': 'assigned_user_id'
        }
    })
    .populateRelate(contact)
    .format();

//open drawer
app.drawer.open({
    layout: 'selection-list',
    context: {
        module: 'Accounts',
        filterOptions: filterOptions,
        parent: this.context
    }
});