Sugarcrm支持产品指南糖开发人员糖开发人员指南11.0建筑学糖逻辑依赖行动设定值

设定值

概述

The SugarLogic 设定值 action, located in ./include/Expressions/Actions/SetValueAction.php, is used to set the value of a field based on a formula.

执行

While the dependency metadata for your module can be defined in ./modules/<module>/metadata/dependencydefs.php and  ./custom/modules/<module>/metadata/dependencydef.php, it is recommended to use the 扩展框架 自定义库存模块以防止第三方插件与您的自定义相冲突。以下部分将演示如何实现只读依赖项。

设定值参数

范围 类型 描述
目标 细绳 用于定位可见性的字段的名称。
价值 细绳 SugarLogic Farmulic用于获得目标字段的值。

有关依赖性定义中各种参数的更多信息,请参阅 依赖行动 documentation.

例子

遵循部分概述了可以实现此依赖性的各种方式。

依赖性扩展

对于我们的示例,我们将创建对引线模块的依赖关系,该模块将显示与铅相关的活动的数量。活动由电话,会议,任务,票据和电子邮件组成。示例扩展定义如下所示:

./custom/extension/modules/<module>/ ext/dependencies/custom_phone_alternate.php.

<?php

$dependencies['Leads']['activity_count_dep'] = array(
    'hooks' => array("edit", "view"), //not including save so that the value isn't stored in the DB
    'trigger' => 'true', //Optional, the trigger for the dependency. Defaults to 'true'.
    'onload' => true, //Whether or not to trigger the dependencies when the page is loaded
    'actions' => array(
        array(
            'name' => 'SetValue',
            'params' => array(
                'target' => 'activity_count_c',
                'value' => 'add(
                    count($notes),
                    count($calls),
                    count($emails),
                    count($meetings),
                    count($tasks)
                )'
            )
        )
    )
);

有文件到位后,您需要导航到管理员> Repairs >并进行快速修复和重建。

笔记:重要的是,模块名称是复数(“案例”与“案例”)并且在此示例中依赖的名称“Activity_Count_Dep”是唯一的。

链接依赖性

您还可以添加尽可能多的操作,根据需要进行数组。在下面的示例中,我们希望显示我们的计数值,但防止用户能够编辑值。示例扩展定义如下所示:

<?php

$dependencies['Leads']['number_of_cases_dep'] = array(
    'hooks' => array("edit", "view"), //not including save so that the value isn't stored in the DB
    'trigger' => 'true', //Optional, the trigger for the dependency. Defaults to 'true'.
    //'triggerFields' => array('status'), //unneeded for this example as its not field triggered
    'onload' => true,
    'actions' => array(
        array(
            'name' => 'SetValue',
            'params' => array(
                'target' => 'activity_count_c',
                'value' => 'add(
                    count($notes),
                    count($calls),
                    count($emails),
                    count($meetings),
                    count($tasks)
                )'
            )
        ),
        array(
            'name' => 'ReadOnly',
            'params' => array(
                'target' => 'activity_count_c',
                'value' => 'true',  //Set to true instead of a formula because its always read-only
            ),
        )
    )
);

有文件到位后,您需要导航到管理员> Repairs >并进行快速修复和重建。

笔记:重要的是,模块名称是复数(“案例”与“案例”),并且在此示例中的依赖项的名称“number_of_cases_dep”是唯一的。

字段定义中的依赖关系

Unlike several of the other dependencies, 设定值 is built into Studio.  So this dependency can be set as a custom vardef value or in the vardefs file of a custom module.  If you wanted to add this dependency to an existing field then you can create a vardef extension such as ./custom/extension/modules/<module>/Ext/Vardefs/. An example extension definition is shown below:

./custom/extension/modules/Accounts/Ext/Vardefs/activity_count_c.php

<?php

$dictionary['Lead']['fields']['activity_count_c']['options'] = 'numeric_range_search_dom';
$dictionary['Lead']['fields']['activity_count_2_c']['calculated'] = 'true';
$dictionary['Lead']['fields']['activity_count_2_c']['formula'] = 'add(
    count($calls),
    count($emails),
    count($meetings),
    count($notes),
    count($tasks)
)';
$dictionary['Lead']['fields']['activity_count_2_c']['enforced'] = 'true';
$dictionary['Lead']['fields']['activity_count_2_c']['enable_range_search'] = '1';

有文件到位后,您需要导航到管理员> Repairs >并进行快速修复和重建。

 

最后修改:2021-02-17 02:44:13