我正在尝试使用SuiteScript 2.0为NetSuite中的记录类型添加一些自定义验证。
在客户端,我已经能够使用客户端脚本在提交之前验证字段。这很好用,并显示一个用户友好的错误消息,解释什么是错误。
在服务器端,使用用户事件脚本,我也执行相同的验证。这会捕获不使用客户端脚本的其他来源(例如CSV上传)的违规行为。如果发现违规,脚本将使用错误模块抛出错误(例如,throw error.create({...}))
但是,用户可以执行某些操作(例如,在记录的视图屏幕上按空格按钮),这些操作不使用客户端脚本,而是修改记录。如果用户事件脚本检测到违规,则最终会在空白屏幕上显示错误消息(格式为json)。不是最友好的用户。
至少有没有办法在空白屏幕上显示未使用JSON格式化的消息?理想情况下,使用message.create / show module在与屏幕相同的屏幕上显示错误消息会很不错。
答案 0 :(得分:1)
由于toString和toJSON函数的覆盖不可用,我建议使用CSS解决方案,仅使用所需的文本替换原始JSON输出。只需使用消息...
添加您的css表达式试试这个:
beforeSubmit: function(scriptContext) {
var errorText = 'This is the error',
msg = '<style>.text {display: none;}' // this will hide the JSON message
+ '.bglt td:first-child:not(.textboldnolink):after {'
+ 'color:black;font-size:8pt;' // set the desired css for our message
+ 'content: url(/images/5square.gif) \''
+ errorText
+ '\'}'
+ '</style>',
err = error.create({
name: 'NO_JSON',
message: msg,
notifyOff: true
});
throw err;
}
您还可以删除&#39;通知(SuiteScript)&#39;使用:
var msg = '<style>'
+ '.text {display: none;}'
+ '.bglt td:first-child:not(.textboldnolink):after {'
+ 'color:red;'
+ 'content: \''
+ errorText
+ '\'}'
+ '.textboldnolink {display: none;}'
+ '</style>';