来自用户事件脚本(SuiteScript 2.0)的用户友好错误消息? [英] User-friendly error message from user event script (SuiteScript 2.0)?

查看:126
本文介绍了来自用户事件脚本(SuiteScript 2.0)的用户友好错误消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用SuiteScript 2.0向NetSuite中的记录类型添加一些自定义验证.

I'm attempting to add some custom validation to a record type in NetSuite using SuiteScript 2.0.

在客户端,我已经能够使用客户端脚本在提交之前验证字段.这样效果很好,并显示了一条用户友好的错误消息,说明出了什么问题.

On the client side, I've been able to use a client script to validate fields before submit. This works well and shows a user-friendly error message explaining what's wrong.

在服务器端,我还使用用户事件脚本执行相同的验证.这会捕获其他不使用客户端脚本的来源(例如CSV上传)的违规行为.如果发现违规,脚本会使用错误模块抛出错误(例如throw error.create({...}))

On the server side, using a user event script, I also perform the same validation. This catches violation from other sources (e.g. CSV upload) which don't use the client script. If a violation is found, the script throws an error using the error module (e.g. throw error.create({...}))

但是,用户可以执行某些操作(例如,在记录的查看屏幕上按无效"按钮),这些操作不使用客户端脚本而是修改记录.如果用户事件脚本检测到违规,它将最终在黑屏上显示错误消息(以json格式).不是最用户友好的.

However, there are certain actions the user can perform (e.g. pressing void button on the record's view screen) which don't use the client script yet modify the record. If the user event script detects a violation, it ends up showing an error message (formatted in json) on a blank screen. Not the most user friendly.

至少有一种方法可以在黑屏上显示未使用JSON格式的消息吗?理想情况下,最好使用message.create/show模块在与按钮相同的屏幕上显示错误消息.

At a minimum, is there a way to show a message on the blank screen that isn't formatted in JSON? Ideally, it would be nice to show the error message on the same screen as the button using the message.create/show module.

推荐答案

由于toString和toJSON函数的覆盖不可用,因此我建议使用CSS解决方案,该解决方案仅将原始JSON输出替换为所需的文本.只需在消息中添加css表达式即可...

Since the overriding of toString and toJSON functions are not available, i suggest using CSS solution that replaces the original JSON output with the desired text only. Just add your css expression with the message...

尝试一下:

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;
}

您还可以使用以下方法删除通知(SuiteScript)":

You can also remove 'Notice (SuiteScript)' by using:

var msg = '<style>' 
            + '.text {display: none;}' 
            + '.bglt td:first-child:not(.textboldnolink):after {'
            + 'color:red;'
            + 'content: \''
            +  errorText 
            + '\'}' 
            + '.textboldnolink {display: none;}' 
            + '</style>';

这篇关于来自用户事件脚本(SuiteScript 2.0)的用户友好错误消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆