Netsuite SS2.0在记录上显示消息
我想使用SS2.0和“新”N/ui/message模块在用户查看记录时显示警告或错误。实际上,我想了解如何在记录视图上运行任何2.0客户端脚本代码 我管理了一个可以从控制台运行的示例:Netsuite SS2.0在记录上显示消息,netsuite,suitescript,Netsuite,Suitescript,我想使用SS2.0和“新”N/ui/message模块在用户查看记录时显示警告或错误。实际上,我想了解如何在记录视图上运行任何2.0客户端脚本代码 我管理了一个可以从控制台运行的示例: require(['N/currentRecord', 'N/ui/message'], function(curr, mess) { var rec = curr.get(); var status = rec.getValue('status'); if
require(['N/currentRecord', 'N/ui/message'],
function(curr, mess) {
var rec = curr.get();
var status = rec.getValue('status');
if (status === 'Unapproved Payment') {
var myMsg = mess.create({
title: "PAYMENT ERROR",
message: status,
type: mess.Type.ERROR
}).show({
duration: 500000
});
}});
在编辑模式(pageInit或任何位置)下运行良好,但尚未找到在“视图”上加载和执行的方法。这在2.0中可能吗?我还必须使用1.0技巧吗?FWIW以下功能在编辑模式下工作,但在查看模式下不工作。(请参阅我对2016年10月生效的黑客攻击的另一个答案)我怀疑这一问题会在未来的某个时候得到解决,因为类似的代码在SS1.0中已经运行了多年。如果您有业务案例,请向Netsuite提交支持案例 用户事件脚本:
/**
*@NApiVersion 2.x
*@NScriptType UserEventScript
*/
define(['N/record', 'N/log'],
function(record, log) {
function beforeLoad(context) {
log.debug({title:'before load with '+ context.type +' on '+ context.form.title});
//if (context.type != 'view') return;
log.debug({title:'setting client script'});
context.form.clientScriptModulePath = './testSimpleClient.js'; //relative to the user event script file
}
return {
beforeLoad: beforeLoad
};
});
testSimpleClient为:
define(['N/ui/message', 'N/currentRecord'], function(msg, currentRecord){
window.console.log('processing script');
function showMessage(rec) {
window.console.log('record status is '+ rec.getValue('status'));
//if('Pending Approval' == rec.getValue('status')){
var myMsg = msg.create({
title: "PAYMENT ERROR",
message: rec.getValue('status'), //'Please Approve',
type: msg.Type.ERROR
}).show({
duration: 100000
});
//}
}
setTimeout(function(){
showMessage(currentRecord.get());
}, 1500);
});
FWIW以下功能在编辑模式下工作,但在查看模式下不工作。(请参阅我对2016年10月生效的黑客攻击的另一个答案)我怀疑这一问题会在未来的某个时候得到解决,因为类似的代码在SS1.0中已经运行了多年。如果您有业务案例,请向Netsuite提交支持案例 用户事件脚本:
/**
*@NApiVersion 2.x
*@NScriptType UserEventScript
*/
define(['N/record', 'N/log'],
function(record, log) {
function beforeLoad(context) {
log.debug({title:'before load with '+ context.type +' on '+ context.form.title});
//if (context.type != 'view') return;
log.debug({title:'setting client script'});
context.form.clientScriptModulePath = './testSimpleClient.js'; //relative to the user event script file
}
return {
beforeLoad: beforeLoad
};
});
testSimpleClient为:
define(['N/ui/message', 'N/currentRecord'], function(msg, currentRecord){
window.console.log('processing script');
function showMessage(rec) {
window.console.log('record status is '+ rec.getValue('status'));
//if('Pending Approval' == rec.getValue('status')){
var myMsg = msg.create({
title: "PAYMENT ERROR",
message: rec.getValue('status'), //'Please Approve',
type: msg.Type.ERROR
}).show({
duration: 100000
});
//}
}
setTimeout(function(){
showMessage(currentRecord.get());
}, 1500);
});
这是一个有效的例子。这并不好(不是很便携,当然也不利于捆绑),但它可以工作: 服务器端:
/**
*@NApiVersion 2.x
*@NScriptType UserEventScript
*/
define(['N/record', 'N/log', 'N/ui/serverWidget'],
function(record, log, ui) {
function beforeLoad(context) {
log.debug({title:'before load with '+ context.type +' on '+ context.form.title});
if (context.type != 'view') return;
log.debug({title:'setting client script'});
var inline = context.form.addField({
id:'custpage_trigger_it',
label:'not shown',
type: ui.FieldType.INLINEHTML,
});
inline.defaultValue = "jQuery(function($){ require(['/SuiteScripts/testSS2/testSimpleClient'], function(mod){ console.log('loaded'); mod.showMessage();});});</script>";
//context.form.clientScriptModulePath = './testSimpleClient.js';
}
return {
beforeLoad: beforeLoad
};
});
这是一个有效的例子。这并不好(不是很便携,当然也不利于捆绑),但它可以工作: 服务器端:
/**
*@NApiVersion 2.x
*@NScriptType UserEventScript
*/
define(['N/record', 'N/log', 'N/ui/serverWidget'],
function(record, log, ui) {
function beforeLoad(context) {
log.debug({title:'before load with '+ context.type +' on '+ context.form.title});
if (context.type != 'view') return;
log.debug({title:'setting client script'});
var inline = context.form.addField({
id:'custpage_trigger_it',
label:'not shown',
type: ui.FieldType.INLINEHTML,
});
inline.defaultValue = "jQuery(function($){ require(['/SuiteScripts/testSS2/testSimpleClient'], function(mod){ console.log('loaded'); mod.showMessage();});});</script>";
//context.form.clientScriptModulePath = './testSimpleClient.js';
}
return {
beforeLoad: beforeLoad
};
});
基于帮助主题:
A current record instance can be accessed via the following ways:
- The context object that gets passed into the client script entry point.
在视图模式下,只能附加用户事件脚本(加载前)
N/currentRecord模块仅在客户端脚本上运行,这就是它无法工作的原因
请改用N/record模块。基于帮助主题:
A current record instance can be accessed via the following ways:
- The context object that gets passed into the client script entry point.
在视图模式下,只能附加用户事件脚本(加载前)
N/currentRecord模块仅在客户端脚本上运行,这就是它无法工作的原因
改用N/record模块。自2018.2版发布以来,他们在
N/ui/serverWidget
模块中添加了一个名为Form.addPageInitMessage(选项)
的新方法,并且完全按照OP的要求执行
上面的例子应该是这样的
/**
*@NApiVersion 2.0
*@NScriptType UserEventScript
*/
define(['N/ui/serverWidget', 'N/record'],
function(serverWidget, record) {
function beforeLoad(context) {
var rec = context.newRecord;
var status = rec.getValue('status');
if (status === 'Unapproved Payment') {
var myMsg = mess.create({
title: "PAYMENT ERROR",
message: status,
type: mess.Type.ERROR,
duration: 500000
});
context.form.addPageInitMessage({message: myMsg});
}
return {
beforeLoad: beforeLoad
};
});
自2018.2版发布以来,他们在
N/ui/serverWidget
模块中添加了一个名为Form.addPageInitMessage(options)
的新方法,并且完全实现了OP想要的功能
上面的例子应该是这样的
/**
*@NApiVersion 2.0
*@NScriptType UserEventScript
*/
define(['N/ui/serverWidget', 'N/record'],
function(serverWidget, record) {
function beforeLoad(context) {
var rec = context.newRecord;
var status = rec.getValue('status');
if (status === 'Unapproved Payment') {
var myMsg = mess.create({
title: "PAYMENT ERROR",
message: status,
type: mess.Type.ERROR,
duration: 500000
});
context.form.addPageInitMessage({message: myMsg});
}
return {
beforeLoad: beforeLoad
};
});
我认为在加载view事件之前需要SS2。新的调用是:
form.clientScriptModulePath='./clientScriptPath.js'代码>NS示例将路径列为SuiteScripts/clientScriptPath.js,但我希望我建议的表单能起作用。否则,捆绑或打包的(都在它们自己的文件夹中)将被处理。我无法使用clientScriptModule/FileId正确执行这些代码。但完全有可能是用户错误。最后,我将上面的示例包装在jquery事件触发器中,在标记内部,在我添加到beforeLoad UE表单中的内联html元素中。它几乎不可能阅读,易碎且凌乱,但它现在还可以使用/我认为在加载view事件之前需要SS2。新的调用是:form.clientScriptModulePath='./clientScriptPath.js'代码>NS示例将路径列为SuiteScripts/clientScriptPath.js,但我希望我建议的表单能起作用。否则,捆绑或打包的(都在它们自己的文件夹中)将被处理。我无法使用clientScriptModule/FileId正确执行这些代码。但完全有可能是用户错误。最后,我将上面的示例包装在jquery事件触发器中,在标记内部,在我添加到beforeLoad UE表单中的内联html元素中。它几乎不可能阅读,易碎且凌乱,但它现在还可以使用/实际上,带有N/currentRecord的代码在客户端运行良好。参见工作示例Yes。基本上,客户端使用N/currentRecord,服务器端使用N/record。实际上,在客户端使用N/currentRecord的代码效果很好。参见工作示例Yes。基本上,客户端使用N/currentRecord,服务器端使用N/record。我同意这并不理想,但这与我最终使用的解决方案基本相同。(毫不奇怪,你的比我的更清楚。)再次感谢!我同意这并不理想,但它本质上与我最终采用的解决方案相同。(毫不奇怪,你的比我的更清楚。)再次感谢!