I try to add PO item sublist fields to inbound items sublist and my code doesn't work. Error:Cannot read properties of undefined (reading 'load')
function pageInit(scriptContext) {
var purchaseOrder = scriptContext.record.load({
type: record.Type.PURCHASE_ORDER,
id: 'purchaseorder',
isDynamic: true
});
var lines = scriptContext.purchaseOrder.getLineCount({
sublistId: 'item'
});
var sample = scriptContext.purchaseOrder.getValue({
fieldId: 'custcitem_po'
});
if (sample != '' && sample != null) {
for (var i=0; i<lines; i++){
scriptContext.currentRecord.selectNewLine({
sublistId: 'items'
});
scriptContext.currentRecord.setCurrentSublistValue({
sublistId: 'items',
fieldId: 'custrecord_sample',
value: sample,
ignoreFieldChange: true
});
scriptContext.currentRecord.commitLine({
sublistId: 'items'
});
}
}
}
updates: I understand your point and I modified the code:
function pageInit(scriptContext) {
var purchaseOrder = record.load({
type: record.Type.PURCHASE_ORDER,
id: '1234', //works only if I specify the exact ID of a purchase order
isDynamic:true
});
var lines = purchaseOrder.getLineCount({
sublistId: 'item'
});
if (lines>=0){
for (var i=0; i<lines; i++){
scriptContext.currentRecord.selectNewLine({
sublistId: 'items'
});
scriptContext.currentRecord.setCurrentSublistValue({
sublistId: 'items',
fieldId: 'custrecord_sample',
value:purchaseOrder.getSublistValue({
sublistId:'item',
fieldId: 'custcitem_po',
line:i
}),
ignoreFieldChange: true
});
scriptContext.currentRecord.commitLine({
sublistId: 'items'
});
}
}
}
The code works well if the id of the PO is mentioned however, I would like it to be valid for any id. Any idea how to do?
According to the docs (not sure if the link will work netsuite.com/app/help/helpcenter.nl?fid=section_4410597671.html, so you can just use the global search for 'pageInit(scriptContext)') the
scriptContextargument doesn't have arecordproperty. Only thecurrentRecord.Also most likely the
scriptContextdoesn't have thepurchaseOrdereither.Try this, sorry, I couldn't test it of course, not that simple. If it doesn't work, post a comment please.