Sugarcrm 如何阻止用户在默认保存时输入重复记录
我有一个自定义模块,其中有一个电子邮件字段。现在我想停止用户,如果电子邮件已经在数据库中 我想在保存按钮上停止用户并显示错误。比如当必填字段变为空时Sugarcrm 如何阻止用户在默认保存时输入重复记录,sugarcrm,suitecrm,Sugarcrm,Suitecrm,我有一个自定义模块,其中有一个电子邮件字段。现在我想停止用户,如果电子邮件已经在数据库中 我想在保存按钮上停止用户并显示错误。比如当必填字段变为空时 我试图获得一些帮助,但无法理解。注意:我在发布此消息后意识到您正在使用suitecrm,此答案不适用于此,但如果任何使用Sugar的人有此问题,我将保留此答案 有两种方法可以实现这一点,因此我将尽我所能按照我推荐的顺序浏览它们。如果您使用的是Sugar post 7.0.0版本,则此选项适用 1) 第一种方法是手动创建电子邮件地址关系。这种方法将使
我试图获得一些帮助,但无法理解。注意:我在发布此消息后意识到您正在使用suitecrm,此答案不适用于此,但如果任何使用Sugar的人有此问题,我将保留此答案 有两种方法可以实现这一点,因此我将尽我所能按照我推荐的顺序浏览它们。如果您使用的是Sugar post 7.0.0版本,则此选项适用 1) 第一种方法是手动创建电子邮件地址关系。这种方法将使用开箱即用的功能,确保您的系统只跟踪单个电子邮件地址。如果这能满足您的需要,您可以查看本食谱文章,如果您有任何问题,请告诉我: 2) 第二种方法是使用自定义字段,即使用字段验证。有关现场验证的文件可在此处找到: 我将重点关注的代码示例是: 以你为例,我想象你会这样做: 为错误消息创建语言密钥: ./custom/Extension/application/Ext/Language/en\u us.error\u email\u exists\u message.php
<?php
$app_strings['ERROR_EMAIL_EXISTS_MESSAGE'] = 'This email already exists.';
您检查过这个@mrbarletta了吗?谢谢您的回复。实际上,我想在保存时调用ajax按钮,而不是在电子邮件字段上调用focusout,因为它可以被绕过,用户仍然可以单击保存并保存记录。那么这个答案呢
({
extendsFrom: 'RecordView',
initialize: function (options) {
this._super('initialize', [options]);
//reference your language key here
app.error.errorName2Keys['email_exists'] = 'ERROR_EMAIL_EXISTS_MESSAGE';
//add validation tasks
this.model.addValidationTask('check_email', _.bind(this._doValidateEmail, this));
},
_doValidateEmail: function(fields, errors, callback) {
var emailAddress = this.model.get('your_email_field');
//this may take some time so lets give the user an alert message
app.alert.show('email-check', {
level: 'process',
title: 'Checking for existing email address...'
});
//make an api call to a custom (or stock) endpoint of your choosing to see if the email exists
app.api.call('read', app.api.buildURL("your_custom_endpoint/"+emailAddress), {}, {
success: _.bind(function (response) {
//dismiss the alert
app.alert.dismiss('email-check');
//analyze your response here
if (response == '<email exists>') {
errors['your_email_field'] = errors['your_email_field'] || {};
errors['your_email_field'].email_exists = true;
}
callback(null, fields, errors);
}, this),
error: _.bind(function (response) {
//dismiss the alert
app.alert.dismiss('email-check');
//throw an error alert
app.alert.show('email-check-error', {
level: 'error',
messages: "There was an error!",
autoClose: false
});
callback(null, fields, errors);
})
});
},
})