В настоящее время у нас есть SO Order (SO), после нажатия кнопки «Drop Ship» страница перенаправляется на другую страницу для создания заказа Pruchase (PO).
, если значениязахваченный на этапе pageInit, отображение записи занимает много времени (чем больше элементов, тем больше времени).
Таким образом, мы хотим получить некоторые значения для SO, а затем поместить их в PO внутри функции befordLoad,Но я сталкиваюсь с некоторыми проблемами из-за синтаксиса, поэтому не уверен, что он работает для NetSuite.
Мой сценарий выглядит следующим образом:
/**
*@NApiVersion 2.x
*@NScriptType UserEventScript
*/
define(['N/record', 'N/ui/serverWidget', 'N/search'],
function (record, serverWidget, search) {
function beforeLoad(context) {
var rec = record.create({
type: record.Type.PURCHASE_ORDER,
isDynamic: true
});
var rec = context.newRecord;
// var createdFromID = rec.getValue({
// fieldId: 'createdfrom'
// });
log.debug('createdFormID', 'test');
log.debug('createdFormID', createdFromID); // 1765886
if (createdFromID != null && createdFromID.length > 0) {
var so_record = record.load({
type: record.Type.SALES_ORDER,
id: createdFromID,
isDynamic: false
});
if (so_record != null) {
//make sure there is a shipping line in the PO, if, create a new line.
// var recordChanged = checkForShippingLine(rec);
log.debug('context.type', context.type);
if (context.type == 'create') {
try {
var po_lines = rec.getLineCount({
sublistId: 'item'
});
var so_costestimate;
for (var poLineNum = 0; poLineNum < po_lines; poLineNum++) {
// var currIndex = rec.selectLine({
// sublistId: 'item',
// line: poLineNum
// });
var soLineID = rec.getSublistValue({
sublistId: 'item',
fieldId: 'custcol_so_line_id',
line: poLineNum
});
log.debug('soLineID', soLineID);
if (soLineID != null && soLineID.length > 0) {
var soLineNumber = so_record.findSublistLineWithValue({
sublistId: 'item',
fieldId: 'custcol_so_line_id',
value: soLineID
});
so_costestimaterate = so_record.getSublistValue({
sublistId: 'item',
fieldId: 'costestimaterate',
line: soLineNumber
});
// rec.setCurrentSublistValue({
rec.setValue({
// sublistId: 'item',
fieldId: 'custcol_so_est_unit_cost',
// line: poLineNum,
// fireSlavingSync: true,
value: parseFloat(so_costestimaterate)
});
rec.commitLine({
sublistId: "item"
});
} //if (soLineNumInPO != null && soLineNumInPO.length > 0)
else {}
} //for(var poLineNum = 1; poLineNum <= po_lines; poLineNum++)
} catch (error) {}
} //if (context.mode == 'create')
}
}
return true;
}