如何使用外部表单并使用SuiteScript从外部表单检索POST数据?

问题描述 投票:0回答:1

如果有一个外部表单发布了一些安全的用户数据,然后一个想要从表单中获取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
    };
});
iframe suitescript2.0
1个回答
1
投票

您可以使用window.postMessage从外部表单传递数据,并在suitelet上添加客户端脚本以使用window.addEventListener监听数据。

要在表单上附加客户端脚本,您可以使用以下内容

newForm.clientScriptModulePath = './FILE_PATH_TO_CLIENT_SCRIPT';

其中newForm是从form返回的serverWidget.createForm对象,在客户端脚本中,您可以使用pageInit来初始化eventListener。

© www.soinside.com 2019 - 2024. All rights reserved.