我是Suitelet的新手。我的目标是从销售订单重定向到Form Suitelet。
我创建了一个file.js以从userevent脚本重定向到Suitelet。
function afterSubmit(scriptContext) {
if (scriptContext.type != 'delete') {
var salesOrder = scriptContext.newRecord;
var orderId = salesOrder.getValue('tranid');
var customer = salesOrder.getValue('entity');
var date = salesOrder.getValue('trandate');
var total = salesOrder.getValue('total');
var financePrice = salesOrder
.getValue('custbody_rmb_financing_price');
var internalid = salesOrder.id;
var arrParams = {
custparam_orderid : orderId,
custparam_customer : customer,
custparam_date : date,
custparam_total : total,
custparam_financeprice : financePrice,
custparam_id : internalid
};
salesOrder.save({
ignoreMandatoryFields : true
});
redirect.toSuitelet({
scriptId : 'customscript_rmb_salesorderfinance_suite',
deploymentId : 'customdeploy_rmb_salesorderfinance_suite',
params : arrParams
});
}
}
我创建另一个文件来重定向和显示销售订单数据。
function(serverWidget, http, runtime, record) {
/**
* Definition of the Suitelet script trigger point.
*
* @param {Object}
* context
* @param {ServerRequest}
* context.request - Encapsulation of the incoming
* request
* @param {ServerResponse}
* context.response - Encapsulation of the Suitelet
* response
* @Since 2015.2
*/
function processSalesOrderFinancing(context) {
if (context.request.method == 'GET') {
var form = serverWidget.createForm('Sales Order Financing');
form
.addField({
id : 'custpage__sdr_financing_help',
type : 'help',
label : 'Please assign a price to the financing of this sales order, then click Submit Financing'
});
var scriptObj = runtime.getCurrentScript();
var stOrder =
scriptObj.getParameter("custparam_orderid");
var stCustomer = scriptObj.getParameter("custparam_customer");
var stDate = scriptObj.getParameter("custparam_date");
var stTotal = scriptObj.getParameter("custparam_total");
var orderid = form.addField({
id : 'custpage_rmb_order',
type : 'text',
label : 'order#'
});
form.updateDefaultValues({
custpage_rmb_order : stOrder
});
orderid.updateDisplayType({
displayType : serverWidget.FieldDisplayType.INLINE
});
var customer = form.addField({
id : 'custpage_rmb_customer',
type : 'text',
label : 'Customer:Project'
});
form.updateDefaultValues({
custpage_rmb_customer : stCustomer
});
customer.updateDisplayType({
displayType : serverWidget.FieldDisplayType.INLINE
});
var date = form.addField({
id : 'custpage_rmb_date',
type : 'date',
label : 'Date'
});
date.updateDisplayType({
displayType : serverWidget.FieldDisplayType.INLINE
});
form.updateDefaultValues({
custpage_rmb_date : stDate
});
var total = form.addField({
id : 'custpage_rmb_total',
type : 'currency',
label : 'Total'
});
form.updateDefaultValues({
custpage_rmb_total : stTotal
});
total.updateDisplayType({
displayType : serverWidget.FieldDisplayType.INLINE
});
var financeprice = form.addField({
id : 'custpage_rmb_fprice',
type : 'currency',
label : 'Finance Price'
});
var salesID = form.addField({
id : 'custpage_rmb_orderid',
type : 'text',
label : 'LABEL'
});
salesID.updateDisplayType({
displayType : serverWidget.FieldDisplayType.HIDDEN
});
form.addSubmitButton('Submit Financing RMB');
context.response.writePage({
pageObject : form
});
} }
在该代码之后,我没有获得销售订单上的数据
表格。我没有得到想要的结果。
getParameter
返回null。如果您有什么想法可以帮助我,我将很感激。
最佳答案
当您使用runtime.getCurrentScript().getParameter()
函数时,您尝试检索在脚本部署记录上定义的参数。
当您使用redirect.toSuitelet()
函数并传递params
属性时,它将把这些参数附加到URL的末尾。要从Suite中从那里访问参数,您应该使用
var stCustomer = context.request.parameters['custparam_customer'];
编辑以添加完整的示例:
用户事件脚本
define(['N/log', 'N/redirect'], function (log, redirect) {
function afterSubmit() {
var arrParams = {
custparam_customer: 1234
};
redirect.toSuitelet({
scriptId: 'customscript_suitelet_test',
deploymentId: 'customdeploy_suitelet_test',
parameters: arrParams
});
}
return {
afterSubmit: afterSubmit
};
});
小套房
define(['N/log', 'N/ui/serverWidget'], function (log, ui) {
function onRequest(context) {
if (context.request.method === 'GET') {
var form = buildForm();
context.response.writePage(form);
}
function buildForm() {
var form = ui.createForm({title: 'Test Params'});
var customerField = form.addField({
id: 'custpage_customer',
type: 'text',
label: 'Customer Param'
}).updateDisplayType({ displayType: ui.FieldDisplayType.INLINE });
customerField.defaultValue = context.request.parameters['custparam_customer'];
return form;
}
}
return {
onRequest: onRequest
};
});
结果是: