我已经在使用加载前用户事件功能的销售订单创建模式下创建了列表/记录,每当我选择一个客户时,该字段中就会填充该客户的销售订单列表,并且我们可以选择其中任何一个。 在列表/记录字段中选择客户和销售订单后,我将单击一个自定义按钮,该按钮将调用套件并在suitlet中创建新销售订单后通过传递的信息创建销售订单,我将页面重定向到新创建的销售订单,因此在这个时间点上,我想创建一条确认消息,例如成功创建了销售订单,我如何在此处创建重定向消息 这是我的代码: 用户事件脚本:
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
define(['N/record', 'N/log','N/ui/serverWidget'],
function(record,log,serverWidget) {
/**
* Function definition to be triggered before record is loaded.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.newRecord - New record
* @param {string} scriptContext.type - Trigger type
* @param {Form} scriptContext.form - Current form
* @Since 2015.2
*/
function beforeLoad(scriptContext) {
if(scriptContext.type===scriptContext.UserEventType.CREATE)
{
var Form=scriptContext.form
var button=Form.addButton({
id : 'custpage_salesorder',
label : 'CREATE SO',
functionName :'createso'
});
log.debug(button);
Form.clientScriptFileId = 5135;
var field = Form.addField({
id : 'custpage_listofsales',
type : serverWidget.FieldType.SELECT,
label : 'list',
source: null
});
log.debug(field);
field.setHelpText({
help : "This field automatically get populated with the sales orders of the selected customer field"
});
}
}
return {
beforeLoad: beforeLoad
};
});
client:
/**
* Script Type : Client script
* Script Name : FEASIBILITY_cs
* Script Author : S.NARENDRA REDDY.
* Script Version : 2.0
* Script Created Date : 16-AUG-2018
*
* Last Modified Date : 17-AUG-2018
* Last Modified By : -----
* Modified Comments : -----
*
* Script Description : 1.Purpose: TO auto populate line items fetched from a sales order selected from list/record field
2.Input: Triggered from UI.
3.Output: Based on USer actions, Script will populate the line items in current record.
4.Search : NA
*/
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
define(['N/currentRecord','N/record','N/search','N/url','N/ui/message','N/https'],
function(currentRecord,record,search,url,message,https) {
function createso()
{
//alert('triggered');
var currentRec=currentRecord.get();
var customer = currentRec.getValue({
fieldId: 'entity'
});
//alert(customer);
log.debug(customer);
var replicaSalesorder = currentRec.getValue({
fieldId: 'custpage_listofsales'
});
// alert(replicaSalesorder);
log.debug(replicaSalesorder);
var suiteUrl = url.resolveScript({
scriptId: 'customscript1424',
deploymentId: 'customdeploy1',
returnExternalUrl: false,
params: {'entity':customer,'salesId':replicaSalesorder}
});
log.debug(suiteUrl);
window.open(suiteUrl,'_self');
var response = https.get({
url: suiteUrl
});
log.debug({title:'response getting',details:response});
if(response.body){
log.debug('entered in response block');
log.debug({title:'response getting',details:response.body});
var myMsg = message.create({
title: "My Title",
message: "My Message",
type: message.Type.CONFIRMATION
});
myMsg.show({ duration : 1500 });
}
}
/**
* Function to be executed when field is changed.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @param {string} scriptContext.sublistId - Sublist name
* @param {string} scriptContext.fieldId - Field name
* @param {number} scriptContext.lineNum - Line number. Will be undefined if not a sublist or matrix field
* @param {number} scriptContext.columnNum - Line number. Will be undefined if not a matrix field
*
* @since 2015.2
*/
function fieldChanged(scriptContext) {
if(scriptContext.fieldId == 'entity')
{
var currentRecord = scriptContext.currentRecord;
log.debug({
title:'currentrecord',
details:JSON.stringify(currentRecord)
});
log.debug('field='+scriptContext.fieldId);
var customer=currentRecord.getValue({fieldId:'entity'});
log.debug('selected customer is'+customer);
var objField = currentRecord.getField({
fieldId: 'custpage_listofsales'
});
var date=new Date();
var year=date.getYear()+1900;
var fdate='1/1/'+year;
var tdate='12/31/'+year;
var mySalesOrderSearch = search.create({
type: search.Type.SALES_ORDER,
title: 'My SalesOrder Search',
columns: [{
name: 'entity'
}, {
name:'internalid'
},
{
name:'tranid'
}],
filters: [{
name: 'mainline',
operator: 'is',
values: ['T']
},
{
name:'entity',
operator: 'is',
values: [customer]
}, {
name: 'trandate',
operator: 'within',
values:[fdate,tdate]
}]
})
var searchResult = mySalesOrderSearch.run().getRange({
start: 0,
end: 100
});
log.debug('results'+searchResult.length);
for (var i = 0; i < searchResult.length; i++) {
var internalid = searchResult[i].getValue({
name: 'internalid'
});
var tranid = searchResult[i].getValue({
name: 'tranid'
});
objField.insertSelectOption({
value : internalid,
text : 'salesorder #'+tranid
});
}
}
}
return {
createso:createso,
fieldChanged: fieldChanged
};
});
suitlet script:
/**
* @NApiVersion 2.x
* @NScriptType Suitelet
* @NModuleScope SameAccount
*/
define(['N/record','N/url','N/redirect','N/ui/serverWidget'],
function(record,url,redirect,ui) {
/**
* 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 onRequest(context) {
try{
var request=context.request;
var customer = request.parameters.entity;
var replicasalesorder=request.parameters.salesId;
log.debug(customer);
log.debug(replicasalesorder);
var custSalesOrd = record.load({
type: record.Type.SALES_ORDER,
id:replicasalesorder ,
//isDynamic: true,
});
var numLines = custSalesOrd.getLineCount({
sublistId: 'item'
});
var salesOrd_item = new Array();
var salesOrd_quantity=new Array();
var salesOrd_units=new Array();
var salesOrd_taxcode=new Array();
var salesOrd_amount=new Array();
var salesOrd_rate=new Array();
var salesOrd_pricelevel=new Array();
for(var i=0;i<numLines;i++)
{
salesOrd_pricelevel[i] = custSalesOrd.getSublistValue({
sublistId: 'item',
fieldId:'price',
line: i
});
//alert('the price level is'+salesOrd_pricelevel[i]);
salesOrd_item[i] = custSalesOrd.getSublistValue({
sublistId: 'item',
fieldId:'item',
line: i
});
//alert('the'+i+'th item is'+salesOrd_item[i]);
salesOrd_quantity[i] = custSalesOrd.getSublistValue({
sublistId: 'item',
fieldId:'quantity',
line: i
});
//alert('the'+i+'th item quantity is'+salesOrd_quantity[i]);
salesOrd_units[i] = custSalesOrd.getSublistValue({
sublistId: 'item',
fieldId:'units',
line: i
});
//alert('the'+i+'th item units is'+salesOrd_units[i]);
salesOrd_taxcode[i] = custSalesOrd.getSublistValue({
sublistId: 'item',
fieldId:'taxcode',
line: i
});
//alert('the'+i+'th item taxcode is'+salesOrd_taxcode[i]);
salesOrd_amount[i] = custSalesOrd.getSublistValue({
sublistId: 'item',
fieldId:'amount',
line: i
});
//alert('the'+i+'th item amount is'+salesOrd_amount[i]);
salesOrd_rate[i] = custSalesOrd.getSublistValue({
sublistId: 'item',
fieldId:'rate',
line: i
});
//alert('the'+i+'th item rate is'+salesOrd_rate[i]);
}
var currentRecord = record.create({
type: record.Type.SALES_ORDER,
isDynamic: true,
});
var custSet=currentRecord.setValue({
fieldId: 'entity',
value: customer,
// ignoreFieldChange: true
});
log.debug({
title: 'Debug Entry',
details: 'Value of var1 is: ' + custSet
});
for(var j=0;j<numLines;j++)
{
try{
log.debug('new line is selected');
/* setting a new line*/
currentRecord.selectNewLine({
sublistId: 'item'
});
/* setting the sublist values for current sales order*/
//alert('price level is being set');
var set=currentRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'item',
value:salesOrd_item[j],
ignoreFieldChange: false,
fireSlavingSync: true
});
//alert('item is being set');
currentRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'quantity',
value:salesOrd_quantity[j],
ignoreFieldChange: false,
fireSlavingSync: true
});
//alert('quantity is being set');
currentRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'units',
value:salesOrd_units[j],
ignoreFieldChange: false,
fireSlavingSync: true
});
//alert('units are being set');
currentRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'price',
value:salesOrd_pricelevel[j],
ignoreFieldChange: false,
fireSlavingSync: true
});
//alert('price level is being set');
currentRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'rate',
value:salesOrd_rate[j],
ignoreFieldChange: false,
fireSlavingSync: true
});
currentRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'amount',
value:salesOrd_amount[j],
ignoreFieldChange: false,
fireSlavingSync: true
});
//alert('amount is being set');
/*currentRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'taxcode',
value:salesOrd_taxcode[j],
ignoreFieldChange: false,
fireSlavingSync: true
});*/
//alert('taxcode is being set');
var comitted=currentRecord.commitLine({
sublistId: 'item'
});
}
catch(error){log.error({
title: 'Error Entry',
details: 'Value of var1 is: ' + error
});
return error;
}
}
var recordId = currentRecord.save({
// enableSourcing: true,
ignoreMandatoryFields: true
});
log.debug(recordId);
context.response.write("+recordId+");
var Redirect=redirect.toRecord({
type : record.Type.SALES_ORDER,
id : recordId,
isEditMode:false
});
}
catch(error){log.error({
title: 'Error Entry',
details: 'Value of var1 is: ' + error
});}
}
return {
onRequest: onRequest
};
});
通过上面的脚本,我得到了显示的消息,但是甚至在页面重定向之前也显示了该消息