suitescript - 如何在 Suitelet 发布上下文中显示客户端警报?
问题描述
在将数据输入此套件表单时,如何显示错误,以便我可以显示如下有关重复 ID 记录的消息?这是否需要在客户端脚本中完成,套件是否需要有一个与执行记录创建的客户端脚本链接的按钮,然后重定向到另一个显示表单信息的套件?似乎必须有一种更简单的方法来显示客户端错误,而无需重定向两次。
套件示例:
define([ 'N/ui/serverWidget', 'N/record', 'N/cache'],
function( serverWidget, record, cache) {
function onRequest(context) {
var func = 'Suitelet';
var request = context.request;
if(request.method == 'GET'){
try{
var form = serverWidget.createForm({
title: 'Add sample data'
});
var idField = form.addField({
id: 'custpage_sample_id',
type: serverWidget.FieldType.TEXT,
label: 'ID'
});
idField.isMandatory = true;
form.addSubmitButton({
label: 'Submit'
});
context.response.writePage(form);
}
catch(e){
log.error(func, JSON.stringify(e));
}
}
else {
try{
var id = request.parameters.custpage_id;
log.debug(func, id);
if(Id){
var existing = getExistingId(Id);
if(!existing){
var custID = createIdRecord(id);
} else {
throw 'ID already exists '+ id;
}
}
var form = serverWidget.createForm({
title: 'Form Submitted'
});
var displayField = form.addField({
id: 'custpage_my_display',
type: serverWidget.FieldType.LONGTEXT,
label: 'Display Data'
});
displayField.defaultValue = "ID: " + id;
context.response.writePage(form);
}
catch(e){
log.error(func, JSON.stringify(e));
}
}
}
return {
onRequest: onRequest
};
});
解决方案
除了“提交”按钮之外,您不需要其他按钮。但是您确实需要将套件与客户端脚本链接:
form.clientScriptFileId = client_script_file_id;
您的客户端脚本不需要部署,您只需要在文件柜上使用它。用户单击提交按钮后,将在链接到套件的客户端脚本上触发 saveRecord 事件。
function saveRecord(context) {
//put your duplicate id logic validation here
if(you want to proceed){
return true;
}else {
alert('duplicate id'); // or display an hidden field with any error message
return false;
}
}
推荐阅读
- swift - Swift 中的枚举和泛型
- javascript - 根据另一个下拉列表禁用下拉列表中的多个值
- linux - 无法从 jenkins 管道中运行 shell 脚本
- deeplearning4j - DL4J/ND4J:INDArray 实例可以重复使用吗?
- powershell - 模板验证错误 - 错误:代码=无效模板;Message=部署模板验证失败:
- javascript - 遍历一个字符串数组并获得一个新字符串
- java - 如何防止 Android hackig 应用程序泄露 Admob 广告 ID
- sql - 如何从 sql 数据透视表中删除空值?
- javascript - 通过可见或隐藏查找元素不起作用
- javascript - 单击按钮的标题或按钮的图标后,按钮的事件不起作用