简体   繁体   English

分离Suite的POST请求

[英]Separating the POST requests of a Suitelet

My goal is to attach a custom Submit button to a Suitelet that sends a post request to an external server. 我的目标是将自定义的“提交”按钮附加到Suitelet,以将发布请求发送到外部服务器。 The problem I am having is that when rendering the page the function send() within my custom button in form.addButton('submit','Submit', send(form)); 我遇到的问题是,在呈现页面时,在form.addButton('submit','Submit', send(form));自定义按钮中使用send()函数form.addButton('submit','Submit', send(form)); is running when the page is loaded. 页面加载时正在运行。 Because of this, no data is being sent to the send() function and therefore not being handled properly. 因此,没有数据被发送到send()函数,因此没有得到正确处理。

From what I understand, this problem has to do with the original POST request rendering the Suitelet and then interfering with the POST request I want to send. 据我了解,该问题与呈现Suitelet的原始POST请求有关,然后干扰了我要发送的POST请求。 What I need to do is separate or differentiate the POST request that renders the form from the one that sends the form. 我需要做的是将呈现表单的POST请求与发送表单的POST请求分开或加以区分。 The ideal would be to have this done in a User Event Script but forms can only be used in Suitelets in SS1.0... 理想的做法是在用户事件脚本中完成此操作,但是表单只能在SS1.0中的Suitelets中使用...

Is there any way this is possible? 有什么办法可行吗? Should I use SuiteScript 2.0 to achieve this? 我应该使用SuiteScript 2.0实现这一目标吗? Below is how my code looks: 以下是我的代码的外观:

function main(request, response){
        var form = nlapiCreateForm('Submission Form');
        form.addField('one', 'text', 'Field 1');
        response.writePage(form);
        form.addButton('submit','Submit', send(form));      
}

function send(form){ process form data somewhere... }

When you are doing send(form) on the Suitelet you are actually running the function. 在Suitelet上执行send(form)时,实际上是在运行该功能。 The form.addButton method 3rd parameter accepts a string, so you want to do something like form.addButton方法的第3个参数接受一个字符串,因此您需要执行类似的操作

form.addButton('submit','Submit', "alert('Sending form')")

You can add a whole stringified function if you want to build your own POST, although I think it would be easier to just include a form.addSubmitButton(label) and that sends the form data to the same Suitelet and from there you can just send that data by POST using nlapiRequestURL 如果您想构建自己的POST,则可以添加整个字符串化函数,尽管我认为只包含form.addSubmitButton(label)会更容易,该方法会将表单数据发送到同一Suitelet,然后您就可以发送了通过POST使用nlapiRequestURL收集该数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM