如果有一个外部表单发布了一些安全的用户数据,然后一个想要从表单中获取POST数据流入NetSuite,有没有办法在SuiteScript中实现这一点?使用iframe显示表单的简单示例:
define(['N/ui/serverWidget'],
function(serverWidget) {
function onRequest(context) {
var func = 'test';
var request = context.request;
var url = 'https://www.sample.com/sample-form.html'; // Not a real form
var title = 'TEST';
if(request.method == 'GET') {
try {
var content = '<iframe width=960px height=100% style="height:640px;" src=' + url + '></iframe>'
var newForm = serverWidget.createForm({
title: title
});
var newField = newForm.addField({
id: 'custpage_form',
type: serverWidget.FieldType.INLINEHTML,
label: 'TEST'
});
newField.defaultValue = content;
context.response.writePage(newForm);
}
catch(e){
log.error(func, JSON.stringify(e));
}
}
else {
}
}
return {
onRequest: onRequest
};
});
您可以使用window.postMessage
从外部表单传递数据,并在suitelet上添加客户端脚本以使用window.addEventListener
监听数据。
要在表单上附加客户端脚本,您可以使用以下内容
newForm.clientScriptModulePath = './FILE_PATH_TO_CLIENT_SCRIPT';
其中newForm
是从form
返回的serverWidget.createForm
对象,在客户端脚本中,您可以使用pageInit来初始化eventListener。